/*
analyse_rii
started 3/21/2020
paul stainier
*/

clear all
set scheme s2mono

***************************
*replace with own directories
***************************
local input = 
local path = 
local output = 
local sum_path =
local sum_path10 = 
local sum_graph_path = 
local table_path = 
local table_region_path = 
local table_path10 = 
local graph_path 
local table_coef_path 
local weather_input = 
local log_path = 
local crosswalk_path = 


***************************
*toggle yes/no to decide
*which programs to run
***************************
local stata_prep_core = "yes"
local stata_prep_10 = "yes"
local summary_by_region = "yes"
local summary_stats = "yes"
local summary_stats10 = "yes"
local summary_icrisat = "yes"
local weather_sum = "yes"
local run_reghdfe_robust = "yes"
local run_reghdfe_firstdiff = "yes"
local run_reghdfe_thresholds = "yes"
local run_reghdfe_s10 = "yes"
local run_reghdfe_icrisat = "yes"
local run_reghdfe_nfhs_by_age = "yes"
local plot_reghdfe_robust = "yes"
local plot_home_purch = "yes"
local plot_reghdfe_s10 = "yes"
local plot_reghdfe_icrisat = "yes"
local plot_reghdfe_nfhs_by_age = "yes"
local plot_reghdfe_thresholds = "yes"




*which weather data to user
local grow_index = "grow"
*local grow_index = "nogrow" 
*local grow_index = "all"


***************************
*
*state_prep_core
*modify variables from the .csv file 
*for schedule 1
*save the core analysis dataset in stata form
*
***************************
if "`stata_prep_core'" == "yes"{
	cd `input'
	cap log close
	log using /Users/paulstainier/Dropbox/1_rii/4_analysis/output/log/stata_prep_core.txt, text replace
	insheet using nss_nutrition_era5_weather_2003_2012_all_analysis.csv, clear
	
	*add later price* 
	destring  adjustment* *rati* iron* s_tribe* cal*  protein* zinc* thiamine* riboflavin* niacin* ascorbic_acid* *home_share ag const manuf  log* *perc adult_woman adult_man woman* man* child* male_lt18 female_lt18 married* unmarried*, replace force
	
	*drop households who have 0 needs because all household members were listed as "away" for 30/30 days in the survey
	drop if calories_need_kcal == 0
	
	foreach grow_index in grow nogrow all{
	foreach time_name in last_y`grow_index' two_ya`grow_index' three_ya`grow_index' this_y`grow_index'{
		gen zeros`time_name' = 0 
	}
	}
	
	*define relavent nutrients
	local nutrients calories iron zinc protein thiamine riboflavin niacin ascorbic_acid 
	
	
	*create nutrient thresholds
	local thresholds 40(10)150

	foreach nutrient in `nutrients' {
		gen `nutrient'_home_dummy = `nutrient'_home_share > 0  
		foreach threshold of numlist `thresholds' {
			gen `nutrient'_lt`threshold'p = (`nutrient'_ratio < `threshold'/100) * 100
		}
	}
	
	*drop if the adjustment factor is >2 or < 0.5 (following carpena)
	gen large_adjustment = adjustment_factor > 2 | adjustment_factor < 0.5 
	tab large_adjustment
	drop if large_adjustment == 1 
	
	*number of kids
	gen num_kids = teenage_boy+ child_boy+ infant_boy +teenage_girl+ child_girl+ infant_girl
	
	**************************************
	*adjusted house size by number of kids
	**************************************
	gen house_size_kidshalf = house_size - num_kids + num_kids / 2
	gen house_size_kidsthird = house_size - num_kids + num_kids / 3
	
	
	*make log of nutreints per capita-day
	foreach nutrient in `nutrients'{
		gen `nutrient'_pcd = `nutrient'_pc / 30
		gen log_`nutrient'_pcd = log(`nutrient'_pcd)
		
		*
		gen `nutrient'_pcd_kh = `nutrient'_pcd * house_size /  house_size_kidshalf
		gen `nutrient'_pcd_kt = `nutrient'_pcd * house_size /  house_size_kidsthird
		
		gen log_`nutrient'_pcd_kh = log(`nutrient'_pcd_kh)
		gen log_`nutrient'_pcd_kt = log(`nutrient'_pcd_kt)
	}
	
	foreach nutrient in `nutrients'{
		foreach var in `nutrient'_home_pc `nutrient'_purchase_pc{
		gen `var'_kh = `var' * house_size /  house_size_kidshalf
		gen `var'_kt = `var' * house_size /  house_size_kidsthird
		} 
	}
	
	
	
	*winsorize the outcome variables
	winsor2 calories_ratio iron_ratio zinc_ratio protein_ratio thiamine_ratio riboflavin_ratio niacin_ratio ascorbic_acid_ratio iron*pc calories*pc zinc*pc protein*pc thiamine*pc riboflavin*pc niacin*pc ascorbic_acid*pc  *home_share total* log* num_kids house_size teenage_boy infant_boy teenage_girl infant_girl adult* *home_pc_k* *purchase_pc_k* child* married* unmarried* woman* man* male_lt18 female_lt18, by(round) cuts(1 99) suffix(_w)	
	
	*destring demographic controls that will be used as outcomes:
	destring hindu s_tribe s_caste head_educ religion social_group house_size, replace force
	gen illit_head = head_educ == 0 
	*turn those into percentage 
	replace hindu = hindu * 100 
	replace s_tribe = s_tribe * 100 
	replace illit_head = illit_head * 100 
	replace s_caste = s_caste * 100
	
	
	gen home_cal_perc_w = total_calories_home_w /total_calories_w 
	
	
	*make the home v. away iron/calories in terms of pc/day rather than per month 
	foreach nutrient in `nutrients'{
		gen `nutrient'_home_pcd_w = `nutrient'_home_pc_w / 30
		gen `nutrient'_purchase_pcd_w = `nutrient'_purchase_pc_w / 30
		
		gen `nutrient'_home_pcd_kh_w = `nutrient'_home_pc_kh_w / 30
		gen `nutrient'_purchase_pcd_kh_w = `nutrient'_purchase_pc_kh_w / 30
		
		gen `nutrient'_home_pcd_kt_w = `nutrient'_home_pc_kt_w / 30
		gen `nutrient'_purchase_pcd_kt_w = `nutrient'_purchase_pc_kt_w / 30
	}
	
	
	*make it so that the iron_lt50p / percentage of calories from home 
	*is expressed as a percentage, as well as the ratioes
	foreach var of varlist log*{
		replace `var' = `var'*100
	}
	
	gen year2 = year - 2002
	label var year2 "Year with 2003 = 1"
	gen year2_sq = year2^2
	label var year2_sq "Year with 2003 = 1, squared"
	
	
	*prec like manisha
	foreach grow_index2 in grow nogrow{
		gen rain_shocklast_y`grow_index2' = wetlast_y`grow_index2' - drylast_y`grow_index2'
		gen rain_shockthis_y`grow_index2' = wetthis_y`grow_index2' - drythis_y`grow_index2'
	}
	
	
	*gen district month fixed effects 
	egen distmo = group(distid3 month)
	egen yearmo = group(year month)
	
	*non-kid house_size
	gen non_kids_house_size_w = house_size_w - num_kids_w 
	
	
	drop surv_date2 effort_cat days_away meals_per_day meals_school meals_empl meals_other meals_pay meals_home calories_need_kcal protein_need_g iron_need_mg zinc_need_mg niacin_need_mg riboflavin_need_mg thiamine_need_mg ascorbic_acid_need_mg
	
	duplicates drop
	compress
	save nss_nutrition_era5_weather_2003_2012_all_analysis, replace
	
	
	log close
}


***************************
*
*stata_prep_10
*modify variables from the .csv file 
*for schedule 10
*save the core analysis dataset in stata form
*
***************************
if "`stata_prep_10'" == "yes"{
	cd `input'
	insheet using nss10_employment_era5_weather_2004_2012_analysis.csv, clear
	
	
	foreach grow_index in grow nogrow all{
	foreach time_name in this_y`grow_index' last_y`grow_index' two_ya`grow_index' three_ya`grow_index' next_y`grow_index'{
		gen zeros`time_name' = 0 
	}
	}
	
	
	gen year2 = year - 2002
	label var year2 "Year with 2003 = 1"
	
	destring  in_school_principal working_principal working_at_home_principal working_away_principal ag_at_home_principal ag_away_principal nonag_at_home_principal nonag_away_principal unempl_principal ag_principal const_principal manuf_principal educ_gen_cat nonag_occ_principal ag_wage68 nonag_wage68, replace force
	replace ag_principal = ag_principal * 100
	replace manuf_principal = manuf_principal * 100
	replace const_principal = const_principal * 100
	replace unempl_principal = unempl_principal * 100
	replace working_principal = working_principal * 100
	replace working_at_home_principal = working_at_home_principal * 100
	replace working_away_principal = working_away_principal * 100
	replace in_school_principal = in_school_principal * 100
	replace nonag_occ_principal = nonag_occ_principal * 100
	replace ag_at_home_principal = ag_at_home_principal * 100
	replace ag_away_principal = ag_away_principal * 100
	replace nonag_at_home_principal = nonag_at_home_principal * 100
	replace nonag_away_principal = nonag_away_principal * 100
	
	
	*prec like manisha
	foreach grow_index2 in grow nogrow all{
		gen rain_shocklast_y`grow_index2' = wetlast_y`grow_index2' - drylast_y`grow_index2'
		gen rain_shockthis_y`grow_index2' = wetthis_y`grow_index2' - drythis_y`grow_index2'
	}
	
	compress
	save nss10_employment_era5_weather_2004_2012_analysis, replace
	
}



***************************
*
*summary_by_region
*summary statistics by region
*
***************************
if "`summary_by_region'" == "yes"{
	cd `input'
	use nss_nutrition_era5_weather_2003_2012_all_analysis, clear
	duplicates drop
	destring muslim christian sikh jain buddhist zoro s_tribe s_caste obc iron_lt50p, replace force
	gen tmax_gt90last_ygrow = tmax_gt100last_ygrow + tmax_90_100last_ygrow
	gen tmax_gt90last_yall = tmax_gt100last_yall + tmax_90_100last_yall
	destring head_educ, replace force
	gen literate = head_educ != 0
	replace literate = . if missing(head_educ)
	foreach var in calories_ratio_w iron_ratio_w protein_ratio_w zinc_ratio_w thiamine_ratio_w riboflavin_ratio_w niacin_ratio_w ascorbic_acid_ratio_w{
		replace `var' = `var'*100
	}
	
	foreach var in teenage_boy_w child_boy_w infant_boy_w teenage_girl_w child_girl_w infant_girl_w adult_man_w adult_woman_w house_size_w distid3 year month year state religion social_group head_educ{
		drop if missing(`var')
	}
	
	// Define the nutrients
	local nutrients calories iron zinc protein thiamine riboflavin niacin ascorbic_acid

	// Loop to generate per capita per day variables
	foreach nutrient in `nutrients' {
		gen `nutrient'_per_capday_w = `nutrient'_pc_w / 30
		replace `nutrient'_home_share = `nutrient'_home_share * 100
		replace `nutrient'_home_dummy = `nutrient'_home_dummy * 100
	}

	
	local vars1 num_kids_w house_size_w calories_ratio_w iron_ratio_w protein_ratio_w zinc_ratio_w thiamine_ratio_w riboflavin_ratio_w niacin_ratio_w ascorbic_acid_ratio_w calories_lt*p iron_lt*p zinc_lt*p protein_lt*p thiamine_lt*p riboflavin_lt*p niacin_lt*p ascorbic_acid_lt*p calories_home_share iron_home_share zinc_home_share protein_home_share thiamine_home_share riboflavin_home_share niacin_home_share ascorbic_acid_home_share iron*pcd_w calories*pcd_w protein*pcd_w zinc*pcd_w  thiamine*pcd_w riboflavin*pcd_w niacin*pcd_w ascorbic_acid*pcd_w log_calories_pcd_w log_iron_pcd_w log_zinc_pcd_w log_protein_pcd_w log_thiamine_pcd_w log_riboflavin_pcd_w log_niacin_pcd_w log_ascorbic_acid_pcd_w iron_home_dummy calories_home_dummy protein_home_dummy zinc_home_dummy thiamine_home_dummy riboflavin_home_dummy niacin_home_dummy ascorbic_acid_home_dummy iron_per_capday_w protein_per_capday_w zinc_per_capday_w thiamine_per_capday_w riboflavin_per_capday_w niacin_per_capday_w ascorbic_acid_per_capday_w num_kids adult_lt30_w adult_30_40_w adult_40_50_w adult_50_60_w adult_gte60_w adult_gte50_w adult_female_perc_w child_female_perc_w adult_lt60_female_perc_w adult_gte60_female_perc_w married_adult_perc_w *last_ygrow

	local vars2  calories_per_capday_w 
	
	gen numobs = 1
	bys distid3: gen numdist = 1 if _n == 1 
	
	*merge in the regions
	cd `crosswalk_path'
	merge m:1 state using region6_crosswalk, keepusing(region6)
	keep if _merge == 3
	drop _merge
	
	
	foreach var of varlist `vars1' `vars2'{
		local collapse_list `collapse_list' `var' 
	}
	
	local collapse_list `collapse_list' (sd)
	foreach var of varlist `vars1' `vars2'{
		local collapse_list `collapse_list' sd_`var' = `var'
	}
	
	collapse `collapse_list' (sum) numobs numdist, by(region6)
	format `vars1' sd* %9.2fc 
	format `vars2' %9.0fc 
	cd `sum_path'
	save sum_by_region6, replace
	
	
	cd `sum_path'
	use sum_by_region6, clear
	cd `table_region_path'
	
	format `vars1' sd* %9.2fc 
	format numobs numdist %9.0fc 
	tostring *, replace force usedisplayformat
	
	
	levelsof region6, local(region6s)
	foreach region of local region6s{
		foreach var of varlist *{
				export delim `var' if region6 == "`region'" using "`var'_`region'.txt", novarnames replace delimiter(" ")
		}
	}
}




***************************
*
*summary_stats
*summary statistics for the whole sample
*schedule 1
*
***************************
if "`summary_stats'" == "yes"{
	cd `input'
	use nss_nutrition_era5_weather_2003_2012_all_analysis, clear
	duplicates drop
	destring muslim christian sikh jain buddhist zoro s_tribe s_caste obc iron_lt50p, replace force
	gen tmax_gt90last_ygrow = tmax_gt100last_ygrow + tmax_90_100last_ygrow
	gen tmax_gt90last_yall = tmax_gt100last_yall + tmax_90_100last_yall
	destring head_educ, replace force
	gen literate = head_educ != 0
	replace literate = . if missing(head_educ)
	foreach var in calories_ratio_w iron_ratio_w protein_ratio_w zinc_ratio_w thiamine_ratio_w riboflavin_ratio_w niacin_ratio_w ascorbic_acid_ratio_w{
		replace `var' = `var'*100
	}
	
	foreach var in teenage_boy_w child_boy_w infant_boy_w teenage_girl_w child_girl_w infant_girl_w adult_man_w adult_woman_w house_size_w distid3 year month year state religion social_group head_educ{
		drop if missing(`var')
	}
	
	
	label var calories_ratio_w "Calories Adequacy Percentage"
	label var iron_ratio_w "Iron Adequacy Percentage"
	label var protein_ratio_w "Protein Adequacy Percentage"
	label var zinc_ratio_w "Zinc Adequacy Percentage"
	label var thiamine_ratio_w "Thiamine Adequacy Percentage"
	label var riboflavin_ratio_w "Riboflavin Adequacy Percentage"
	label var niacin_ratio_w "Niacin Adequacy Percentage"
	label var ascorbic_acid_ratio_w "Ascorbic Acid Adequacy Percentage"
	
	cd `sum_graph_path'
						
	twoway kdensity calories_ratio_w, ytitle("Density", placement(n) orientation(horizontal) color(gs1) size(medlarge)) xtitle("Calories Adequacy Percentage")  xline(80 100) xlabel(0 50 80 100 150 200 250 300, nogrid) ylabel(,nogrid) graphregion(fcolor(white) lcolor(white) margin(large)) plotregion(lstyle(white)) ysc(titlegap(-45) outergap(0) lcolor(gs1))
	gr_edit yaxis1.title.DragBy 5 0
	graph export kdens_cal_perc.pdf, replace
	
	twoway kdensity iron_ratio_w, ytitle("Density", placement(n) orientation(horizontal) color(gs1) size(medlarge)) xtitle("Iron Adequacy Percentage")  xline(80 100) xlabel(0 50 80 100 150 200 250 300, nogrid) ylabel(,nogrid) graphregion(fcolor(white) lcolor(white) margin(large)) plotregion(lstyle(white)) ysc(titlegap(-45) outergap(0) lcolor(gs1))
	gr_edit yaxis1.title.DragBy 5 0
	graph export kdens_iron_perc.pdf, replace
	
	twoway kdensity zinc_ratio_w, ytitle("Density", placement(n) orientation(horizontal) color(gs1) size(medlarge)) xtitle("Zinc Adequacy Percentage")  xline(80 100) xlabel(0 50 80 100 150 200 250 300, nogrid) ylabel(,nogrid) graphregion(fcolor(white) lcolor(white) margin(large)) plotregion(lstyle(white)) ysc(titlegap(-45) outergap(0) lcolor(gs1))
	gr_edit yaxis1.title.DragBy 5 0
	graph export kdens_zinc_perc.pdf, replace
	
	twoway kdensity protein_ratio_w, ytitle("Density", placement(n) orientation(horizontal) color(gs1) size(medlarge)) xtitle("Protein Adequacy Percentage")  xline(80 100) xlabel(0 50 80 100 150 200 250 300, nogrid) ylabel(,nogrid) graphregion(fcolor(white) lcolor(white) margin(large)) plotregion(lstyle(white)) ysc(titlegap(-45) outergap(0) lcolor(gs1))
	gr_edit yaxis1.title.DragBy 5 0
	graph export kdens_protein_perc.pdf, replace
	
	twoway kdensity thiamine_ratio_w, ytitle("Density", placement(n) orientation(horizontal) color(gs1) size(medlarge)) xtitle("Thiamine Adequacy Percentage")  xline(80 100) xlabel(0 50 80 100 150 200 250 300, nogrid) ylabel(,nogrid) graphregion(fcolor(white) lcolor(white) margin(large)) plotregion(lstyle(white)) ysc(titlegap(-45) outergap(0) lcolor(gs1))
	gr_edit yaxis1.title.DragBy 5 0
	graph export kdens_thiamine_perc.pdf, replace
	
	twoway kdensity riboflavin_ratio_w, ytitle("Density", placement(n) orientation(horizontal) color(gs1) size(medlarge)) xtitle("Riboflavin Adequacy Percentage")  xline(80 100) xlabel(0 50 80 100 150 200 250 300, nogrid) ylabel(,nogrid) graphregion(fcolor(white) lcolor(white) margin(large)) plotregion(lstyle(white)) ysc(titlegap(-45) outergap(0) lcolor(gs1))
	gr_edit yaxis1.title.DragBy 5 0
	graph export kdens_riboflavin_perc.pdf, replace
	
	twoway kdensity niacin_ratio_w, ytitle("Density", placement(n) orientation(horizontal) color(gs1) size(medlarge)) xtitle("Niacin Adequacy Percentage")  xline(80 100) xlabel(0 50 80 100 150 200 250 300, nogrid) ylabel(,nogrid) graphregion(fcolor(white) lcolor(white) margin(large)) plotregion(lstyle(white)) ysc(titlegap(-45) outergap(0) lcolor(gs1))
	gr_edit yaxis1.title.DragBy 5 0
	graph export kdens_niacin_perc.pdf, replace
	
	twoway kdensity ascorbic_acid_ratio_w, ytitle("Density", placement(n) orientation(horizontal) color(gs1) size(medlarge)) xtitle("Ascorbic Adequacy Percentage")  xline(80 100) xlabel(0 50 80 100 150 200 250 300, nogrid) ylabel(,nogrid) graphregion(fcolor(white) lcolor(white) margin(large)) plotregion(lstyle(white)) ysc(titlegap(-45) outergap(0) lcolor(gs1))
	gr_edit yaxis1.title.DragBy 5 0
	graph export kdens_ascorbic_acid_perc.pdf, replace
	
	local collapse_list (count) num_house = house_id (mean)
	
	
	
	// Define the nutrients
	local nutrients calories iron zinc protein thiamine riboflavin niacin ascorbic_acid

	// Loop to generate per capita per day variables
	foreach nutrient in `nutrients' {
		gen `nutrient'_per_capday_w = `nutrient'_pc_w / 30
		replace `nutrient'_home_share = `nutrient'_home_share * 100
		replace `nutrient'_home_dummy = `nutrient'_home_dummy * 100
	}

	
	local vars1 num_kids_w house_size_w calories_ratio_w iron_ratio_w protein_ratio_w zinc_ratio_w thiamine_ratio_w riboflavin_ratio_w niacin_ratio_w ascorbic_acid_ratio_w calories_lt*p iron_lt*p zinc_lt*p protein_lt*p thiamine_lt*p riboflavin_lt*p niacin_lt*p ascorbic_acid_lt*p calories_home_share iron_home_share zinc_home_share protein_home_share thiamine_home_share riboflavin_home_share niacin_home_share ascorbic_acid_home_share iron*pcd_w calories*pcd_w protein*pcd_w zinc*pcd_w  thiamine*pcd_w riboflavin*pcd_w niacin*pcd_w ascorbic_acid*pcd_w log_calories_pcd_w log_iron_pcd_w log_zinc_pcd_w log_protein_pcd_w log_thiamine_pcd_w log_riboflavin_pcd_w log_niacin_pcd_w log_ascorbic_acid_pcd_w iron_home_dummy calories_home_dummy protein_home_dummy zinc_home_dummy thiamine_home_dummy riboflavin_home_dummy niacin_home_dummy ascorbic_acid_home_dummy iron_per_capday_w protein_per_capday_w zinc_per_capday_w thiamine_per_capday_w riboflavin_per_capday_w niacin_per_capday_w ascorbic_acid_per_capday_w num_kids adult_lt30_w adult_30_40_w adult_40_50_w adult_50_60_w adult_gte60_w adult_gte50_w adult_female_perc_w child_female_perc_w adult_lt60_female_perc_w adult_gte60_female_perc_w married_adult_perc_w

	local vars2  calories_per_capday_w 
	
	
	foreach var of varlist `vars1' `vars2'{
		local collapse_list `collapse_list' `var' 
	}
	
	local collapse_list `collapse_list' (sd)
	foreach var of varlist `vars1' `vars2'{
		local collapse_list `collapse_list' sd_`var' = `var'
	}
	
	gen numobs = 1
	bys distid3: gen numdist = 1 if _n == 1
	
	
	
	preserve
	collapse `collapse_list' (sum) numobs numdist
	save sum_total, replace
	restore 
	
	cd `sum_path'
	use sum_total, clear
	cd `table_path'
	
	format `vars1' sd* %9.2fc 
	format `vars2' numobs %9.0fc 
	tostring *, replace force usedisplayformat
	foreach var of varlist *{
				export delim `var' using "`var'_overall.txt", novarnames replace delimiter(" ")
	}
}




***************************
*
*summary_stats10
*summary statistcs for schedule 10
*
***************************
if "`summary_stats10'" == "yes"{
	
	******principally workers*******
	cd `input'
	use nss10_employment_era5_weather_2004_2012_analysis, clear
	duplicates drop

	keep if working_principal
	local vars1 ag_principal nonag_occ_principal manuf_principal const_principal 

	
	local collapse_list 
	foreach var in `vars1'{
		local collapse_list `collapse_list' `var'
	}
	local collapse_list `collapse_list' (sd)
	foreach var of varlist `vars1'{
		local collapse_list `collapse_list' sd_`var' = `var'
	}
	
	preserve 
	collapse `collapse_list', by(round)
	format `vars1' %9.2fc 
	cd `sum_path10'
	
	la var ag_principal "Share of Workers in Agriculture, Principally"
	la var manuf_principal "Share of Workers in Manufacturing , Principally"
	la var const_principal "Share of Workers in Construction , Principally"
	save sum_by_round_10_principal_workers, replace
	restore
	
	preserve 
	collapse `collapse_list', by(month)
	format `vars1' %9.2fc 
	cd `sum_path10'
	
	la var ag_principal "Share of Workers in Agriculture , Principally"
	la var manuf_principal "Share of Workers in Manufacturing , Principally"
	la var const_principal "Share of Workers in Construction , Principally"
	save sum_by_month_10_principal_workers, replace
	restore
	
	collapse `collapse_list'
	save sum_total_10_principal_workers, replace
	
	
	*make graphs
	foreach c_unit in month round{
		cd `sum_path10'
		use sum_by_`c_unit'_10_principal_workers, clear
		cd `sum_path10'/graphs
		foreach job in ag manuf const{
			*weekly
			egen maxvar = max(`job'_principal)
			local maxvar = maxvar
			local inc_var = round(`maxvar'/4)
			twoway connected `job'_principal `c_unit', ylabel(0(`inc_var')`maxvar')
			graph export sum_`job'_principal_`c_unit'.eps, replace
			drop maxvar
		}
	}
	
	cd `sum_path10'
	use sum_total_10_principal_workers, clear
	cd `table_path10'
	
	format `vars1' sd* %9.2fc 
	tostring *, replace force usedisplayformat
	foreach var of varlist *{
				export delim `var' using "`var'_workers.txt", novarnames replace delimiter(" ")
	}
	
	
	*****percent of people in working age*******
	cd `input'
	use nss10_employment_era5_weather_2004_2012_analysis, clear
	duplicates drop
	keep if work_age == 1
	
	local vars1 working_principal ag_principal nonag_occ_principal manuf_principal const_principal unempl_principal domestic_duties_principal ag_at_home_principal nonag_at_home_principal ag_away_principal nonag_away_principal
	
	local collapse_list 
	foreach var in `vars1'{
		local collapse_list `collapse_list' `var'
	}
	local collapse_list `collapse_list' (sd)
	foreach var of varlist `vars1'{
		local collapse_list `collapse_list' sd_`var' = `var'
	}
	
	preserve
	collapse `collapse_list', by(round)
	la var working_principal "Share of People Working, Principally"
	cd `sum_path10'
	save sum_by_round_adults, replace 
	restore 
	
	preserve
	collapse `collapse_list', by(month)
	la var working_principal "Share of People Working, Principally"
	cd `sum_path10'
	save sum_by_month_adults, replace 
	restore 
	
	collapse `collapse_list'
	la var working_principal "Share of People Working, Principally"
	save sum_total_adults, replace
	
	
	cd `sum_path10'
	use sum_total_adults, clear
	cd `table_path10'
	
	format `vars1' sd* %9.2fc 
	tostring *, replace force usedisplayformat
	foreach var of varlist *{
				export delim `var' using "`var'_workage.txt", novarnames replace delimiter(" ")
	}
	
	*****percent of school age*******
	cd `input'
	use nss10_employment_era5_weather_2004_2012_analysis, clear
	duplicates drop
	keep if school_age == 1
	
	local vars1 working_principal ag_principal nonag_occ_principal in_school_principal
	
	local collapse_list 
	foreach var in `vars1'{
		local collapse_list `collapse_list' `var' 
	}
	local collapse_list `collapse_list' (sd)
	foreach var of varlist `vars1'{
		local collapse_list `collapse_list' sd_`var' = `var'
	}
	
	preserve
	collapse `collapse_list', by(round)
	cd `sum_path10'
	save working_by_round_schoolage, replace 
	restore 
	
	preserve
	collapse `collapse_list', by(month)
	cd `sum_path10'
	save working_by_month_schoolage, replace 
	restore 
	
	collapse `collapse_list'
	save working_total_schoolage, replace
	
	
	cd `sum_path10'
	use working_total_schoolage, clear
	cd `table_path10'
	
	format `vars1' sd* %9.2fc 
	tostring *, replace force usedisplayformat
	foreach var of varlist *{
				export delim `var' using "`var'_schoolage.txt", novarnames replace delimiter(" ")
	}
}


***************************
*
*summary_icrisat
*summary stats for icrisat yield data
*
***************************
if "`summary_icrisat'" == "yes"{
	cd `input'
	
	insheet using icrisat_yield_era5_weather_1981_2011_analysis.csv, clear		

	
	destring lyield lyield_m, replace force
	replace lyield = lyield * 100
	replace lyield_m = lyield_m * 100
	drop if missing(lyield) | missing(lyield_m)
	
	gen numobs = 1
	bys icrisat_district: gen numdist = 1 if _n == 1
	local collapse_list lyield lyield_m 
	destring `collapse_list', replace force
	
	local collapse_list `collapse_list' (sum) numobs numdist (sd) sd_lyield=lyield sd_lyield_m=lyield_m

	cd `sum_path'
	collapse `collapse_list'
	save sum_total_icrisat, replace
	
	cd `sum_path'
	use sum_total_icrisat, clear
	cd `table_path'
	local outcome_vars lyield lyield_m sd_lyield sd_lyield_m
	format `outcome_vars' %9.2fc 
	format numobs numdist %9.0fc 
	tostring *, replace force usedisplayformat
	foreach var in `outcome_vars'{
				export delim `var' using "`var'_overall.txt", novarnames replace delimiter(" ")
	}
	export delim numobs using "icrisat_numobs_overall.txt", novarnames replace delimiter(" ")
	export delim numdist using "icrisat_numdist_overall.txt", novarnames replace delimiter(" ")
	
}


***************************
*
*weather_sum
*era5 weather summary stats
*
***************************
if "`weather_sum'" == "yes"{
	
	*full weather summary stats, growing season, non-growing season, and full year
	*use analysis dataset so the outcomes are weighted by household
	cd `input'
	use nss_nutrition_era5_weather_2003_2012_all_analysis, clear 

	keep if year >= 2003 & year <= 2012
	local collapse_list 
	foreach var in tmax_gt110 tmax_100_110 tmax_90_100 tmax_80_90 tmax_70_80 tmax_lt70 rain_shock prec how_dry how_wet dry wet{
		local collapse_list `collapse_list' `var'last_ygrow `var'last_ynogrow  
	}
	
	
	local collapse_list2 `collapse_list' (sd) 
	foreach var in tmax_gt110 tmax_100_110 tmax_90_100 tmax_80_90 tmax_70_80 tmax_lt70 rain_shock prec how_dry how_wet dry wet{
		local collapse_list2 `collapse_list2' sd_`var'last_ygrow = `var'last_ygrow sd_`var'last_ynogrow = `var'last_ynogrow
	}
	
	collapse (mean) `collapse_list2'
	format tmax* sd* prec* how* dry* wet* rain* %9.2fc
	tostring  tmax* sd* prec* how* dry* wet* rain*, replace force usedisplayformat
	cd `table_path'
	foreach var of varlist tmax* sd* prec* how* dry* wet* rain*{
		export delim `var' using "`var'_overall.txt" , novarnames replace
	}
	
}



***************************
*
*RUN_REGHDFE_ROBUST
*
*run regressions for the 
*core specification
*and robustness
*
***************************
if "`run_reghdfe_robust'" == "yes"{
	*decide which regressions to run and add them to the list 
	*first number refers to the outcome variable
	*second number refers to the regression specification
	

	local reglist
	foreach num of numlist 10(10)870 11(10)131 14(10)134 15(10)135 16(10)136 18(10)138 19(10)119 291 294 295 296 298 299 301 304 305 306 308 309 681 684 685 686 688 689 741 744 745 746 748 749 801 804 805 806 808 809 861 864 865 866 868 869{
		local reglist `reglist' rr`num'
	}
	
	cd `input'
	use nss_nutrition_era5_weather_2003_2012_all_analysis, clear
	

	*drop observations missing variables that are in every specification
	foreach var in teenage_boy_w child_boy_w infant_boy_w teenage_girl_w child_girl_w infant_girl_w adult_man_w adult_woman_w house_size_w distid3 year month year state religion social_group head_educ{
		drop if missing(`var')
	}
	
	gen infant_w = infant_boy_w + infant_girl_w
	
	
	*list of independent variables 
	
	*x1
	local x1 teenage_boy_w child_boy_w infant_boy_w teenage_girl_w child_girl_w infant_girl_w adult_man_w adult_woman_w 
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local x1 `x1'  zeros`time_name' tmax_70_80`time_name'  tmax_80_90`time_name' tmax_90_100`time_name' tmax_100_110`time_name' tmax_gt110`time_name' 
	}
	
	
	*x2
	local x2 house_size_w
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local x2 `x2'  zeros`time_name' tmax_70_80`time_name'  tmax_80_90`time_name' tmax_90_100`time_name' tmax_100_110`time_name' tmax_gt110`time_name'
	}
	
	
	*x3
	local x3  
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local x3 `x3'  zeros`time_name' tmax_70_80`time_name'  tmax_80_90`time_name' tmax_90_100`time_name' tmax_100_110`time_name' tmax_gt110`time_name'
	}
	

	*x5
	local x5 teenage_boy_w child_boy_w infant_boy_w teenage_girl_w child_girl_w infant_girl_w adult_man_w adult_woman_w 
	foreach time_name in last_ygrow last_ynogrow{
		local x5 `x5'  zeros`time_name' tmax_70_80`time_name'  tmax_80_90`time_name' tmax_90_100`time_name' tmax_100_110`time_name' tmax_gt110`time_name' 
	}
	
	*x6
	local x6 teenage_boy_w child_boy_w infant_boy_w teenage_girl_w child_girl_w infant_girl_w adult_man_w adult_woman_w
	foreach time_name in this_ygrow this_ynogrow{
		local x6 `x6'  zeros`time_name' tmax_70_80`time_name'  tmax_80_90`time_name' tmax_90_100`time_name' tmax_100_110`time_name' tmax_gt110`time_name' 
	}
	
	*x7
	local x7 house_size_w 
	foreach time_name in last_ygrow last_ynogrow{
		local x7 `x7'  zeros`time_name' tmax_70_80`time_name'  tmax_80_90`time_name' tmax_90_100`time_name' tmax_100_110`time_name' tmax_gt110`time_name' 
	}
	
	
	
	*fixed effects c.year2##i.state
	*fe1 
	local fe1 distid3 year month c.year2#i.state religion social_group head_educ 
	
	*fe2 
	local fe2 distmo yearmo c.year2#i.state religion social_group head_educ
	
	*fe3
	local fe3 distid3 year month c.year2#i.state
	
	*fe4 
	local fe4 distid3 year month c.year2#i.distid3 religion social_group head_educ 
	
	*fe5 
	local fe5 distid3 year month c.year2#i.state c.year2_sq#i.state religion social_group head_educ
	

	*precipitation variables
	*p0 no prec
	local p0 
	
	*p1
	local p1
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local p1 `p1' rain_shock`time_name' 
	}
	
	*p2
	local p2
	foreach time_name in last_ygrow last_ynogrow{
		local p2 `p2' rain_shock`time_name' 
	}
	
	*p3
	local p3
	foreach time_name in last_ygrow this_ygrow next_ygrow{
		local p3 `p3' rain_shock`time_name' 
	}
	
	*p4
	local p4
	foreach time_name in last_ygrow last_ynogrow  this_ygrow this_ynogrow{
		local p4 `p4' prec`time_name' 
	}
	
	*p5
	local p5
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local p5 `p5' how_dry`time_name' how_wet`time_name' 
	}
	
	*p6
	local p6
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local p6 `p6' dry`time_name' wet`time_name' 
	}
	
	*p7
	local p7
	foreach time_name in this_ygrow this_ynogrow{
		local p7 `p7' rain_shock`time_name' 
	}
	
	
	*define regressions
	*rr#0: district, month, & year fixed effects, state-year trend, demographic controls, rainfall
	*this and last year's weather
	
	*rr10
	local rr10_x x1
	local rr10_y log_calories_pcd_w
	local rr10_fe fe1
	local rr10_p p1
	
	*rr1000
	local rr1000_x x1
	local rr1000_y log_calories_pcd
	local rr1000_fe fe1
	local rr1000_p p1
	
	*rr20
	local rr20_x x1
	local rr20_y calories_home_pcd_w
	local rr20_fe fe1
	local rr20_p p1
	
	*rr30
	local rr30_x x1
	local rr30_y calories_purchase_pcd_w
	local rr30_fe fe1
	local rr30_p p1
	
	*rr40
	local rr40_x x1
	local rr40_y log_iron_pcd_w
	local rr40_fe fe1
	local rr40_p p1
	
	*rr50
	local rr50_x x2
	local rr50_y iron_lt50p
	local rr50_fe fe1
	local rr50_p p1
	
	*rr60
	local rr60_x x1
	local rr60_y iron_home_pcd_w
	local rr60_fe fe1
	local rr60_p p1
	
	*rr70
	local rr70_x x1
	local rr70_y iron_purchase_pcd_w
	local rr70_fe fe1
	local rr70_p p1
	
	*rr80
	local rr80_x x2
	local rr80_y calories_lt100p
	local rr80_fe fe1
	local rr80_p p1
	
	*rr90
	local rr90_x x2
	local rr90_y calories_lt80p
	local rr90_fe fe1
	local rr90_p p1
	
	*rr100
	local rr100_x x2
	local rr100_y iron_lt80p
	local rr100_fe fe1
	local rr100_p p1
	
	*rr110
	local rr110_x x2
	local rr110_y iron_lt100p
	local rr110_fe fe1
	local rr110_p p1
	
	*rr120
	local rr120_x x2
	local rr120_y calories_lt60p
	local rr120_fe fe1
	local rr120_p p1
	
	*rr130
	local rr130_x x2
	local rr130_y iron_lt60p
	local rr130_fe fe1
	local rr130_p p1
	
	*rr140
	local rr140_x x3
	local rr140_y num_kids_w
	local rr140_fe fe1
	local rr140_p p1
	
	*rr150
	local rr150_x x3
	local rr150_y house_size_w
	local rr150_fe fe1
	local rr150_p p1
	
	*rr160
	local rr160_x x3
	local rr160_y non_kids_house_size_w
	local rr160_fe fe1
	local rr160_p p1
	
	*rr170
	local rr170_x x3
	local rr170_y adult_lt30_w  
	local rr170_fe fe1
	local rr170_p p1
	
	*rr180
	local rr180_x x3
	local rr180_y adult_30_40_w
	local rr180_fe fe1
	local rr180_p p1 
	
	*rr190
	local rr190_x x3
	local rr190_y adult_40_50_w
	local rr190_fe fe1
	local rr190_p p1
	
	*rr200
	local rr200_x x3
	local rr200_y adult_50_60_w
	local rr200_fe fe1
	local rr200_p p1
	
	*rr210
	local rr210_x x3
	local rr210_y adult_gte60_w
	local rr210_fe fe1
	local rr210_p p1
	
	*rr220
	local rr220_x x1
	local rr220_y log_protein_pcd_w
	local rr220_fe fe1
	local rr220_p p1
	
	*rr230
	local rr230_x x1
	local rr230_y protein_home_pcd_w
	local rr230_fe fe1
	local rr230_p p1
	
	*rr240
	local rr240_x x1
	local rr240_y protein_purchase_pcd_w
	local rr240_fe fe1
	local rr240_p p1
	
	*rr250
	local rr250_x x1
	local rr250_y log_zinc_pcd_w
	local rr250_fe fe1
	local rr250_p p1
	
	*rr260
	local rr260_x x1
	local rr260_y zinc_home_pcd_w
	local rr260_fe fe1
	local rr260_p p1
	
	*rr270
	local rr270_x x1
	local rr270_y zinc_purchase_pcd_w
	local rr270_fe fe1
	local rr270_p p1
	
	*rr280
	local rr280_x x2
	local rr280_y protein_lt100p
	local rr280_fe fe1
	local rr280_p p1
	
	*rr290
	local rr290_x x2
	local rr290_y protein_lt80p
	local rr290_fe fe1
	local rr290_p p1
	
	*rr300
	local rr300_x x2
	local rr300_y zinc_lt80p
	local rr300_fe fe1
	local rr300_p p1
	
	*rr310
	local rr310_x x2
	local rr310_y zinc_lt100p
	local rr310_fe fe1
	local rr310_p p1
	
	*rr320
	local rr320_x x2
	local rr320_y iron_lt40p
	local rr320_fe fe1
	local rr320_p p1
	
	*rr330
	local rr330_x x3
	local rr330_y adult_gte50_w
	local rr330_fe fe1
	local rr330_p p1
	
	*rr340
	local rr340_x x2
	local rr340_y calories_lt50p
	local rr340_fe fe1
	local rr340_p p1
	
	*rr350
	local rr350_x x2
	local rr350_y protein_lt50p
	local rr350_fe fe1
	local rr350_p p1
	
	*rr360
	local rr360_x x2
	local rr360_y zinc_lt50p
	local rr360_fe fe1
	local rr360_p p1
	
	*rr370
	local rr370_x x2
	local rr370_y child_female_perc_w
	local rr370_fe fe1
	local rr370_p p1
	
	*rr380
	local rr380_x x2
	local rr380_y adult_lt60_female_perc_w
	local rr380_fe fe1
	local rr380_p p1
	
	*rr390
	local rr390_x x2
	local rr390_y adult_gte60_female_perc_w
	local rr390_fe fe1
	local rr390_p p1
	
	*rr400
	local rr400_x x2
	local rr400_y married_adult_perc_w
	local rr400_fe fe1
	local rr400_p p1
	
	*rr410
	local rr410_x x3
	local rr410_y adult_woman_lt60_w
	local rr410_fe fe1
	local rr410_p p1
	
	*rr420
	local rr420_x x3
	local rr420_y adult_man_lt60_w
	local rr420_fe fe1
	local rr420_p p1
	
	*rr430
	local rr430_x x3
	local rr430_y woman_lt30_w
	local rr430_fe fe1
	local rr430_p p1
	
	*rr440
	local rr440_x x3
	local rr440_y man_lt30_w
	local rr440_fe fe1
	local rr440_p p1
	
	*rr450
	local rr450_x x3
	local rr450_y woman_30_40_w
	local rr450_fe fe1
	local rr450_p p1
	
	*rr460
	local rr460_x x3
	local rr460_y man_30_40_w
	local rr460_fe fe1
	local rr460_p p1
	
	*rr470
	local rr470_x x3
	local rr470_y woman_40_50_w
	local rr470_fe fe1
	local rr470_p p1
	
	*rr480
	local rr480_x x3
	local rr480_y man_40_50_w
	local rr480_fe fe1
	local rr480_p p1
	
	*rr490
	local rr490_x x3
	local rr490_y woman_50_60_w
	local rr490_fe fe1
	local rr490_p p1
	
	*rr500
	local rr500_x x3
	local rr500_y man_50_60_w
	local rr500_fe fe1
	local rr500_p p1
	
	*rr510
	local rr510_x x2
	local rr510_y adult_lt30_female_perc_w
	local rr510_fe fe1
	local rr510_p p1
	
	*rr520
	local rr520_x x2
	local rr520_y adult_30_40_female_perc_w
	local rr520_fe fe1
	local rr520_p p1
	
	*rr530
	local rr530_x x2
	local rr530_y adult_40_50_female_perc_w
	local rr530_fe fe1
	local rr530_p p1
	
	*rr540
	local rr540_x x2
	local rr540_y adult_50_60_female_perc_w
	local rr540_fe fe1
	local rr540_p p1
	
	*rr550
	local rr550_x x3
	local rr550_y man_gte60_w
	local rr550_fe fe1
	local rr550_p p1
	
	*rr560
	local rr560_x x3
	local rr560_y woman_gte60_w
	local rr560_fe fe1
	local rr560_p p1
	
	*rr570
	local rr570_x x3
	local rr570_y male_lt18_w
	local rr570_fe fe1
	local rr570_p p1
	
	*rr580
	local rr580_x x3
	local rr580_y female_lt18_w
	local rr580_fe fe1
	local rr580_p p1
	
	*rr590
	local rr590_x x3
	local rr590_y married_woman_lt30_w
	local rr590_fe fe1
	local rr590_p p1
	
	*rr600
	local rr600_x x3
	local rr600_y unmarried_woman_lt30_w
	local rr600_fe fe1
	local rr600_p p1
	
	*rr610
	local rr610_x x3
	local rr610_y married_man_lt30_w
	local rr610_fe fe1
	local rr610_p p1
	
	*rr620
	local rr620_x x3
	local rr620_y unmarried_man_lt30_w
	local rr620_fe fe1
	local rr620_p p1
	
	*rr630
	local rr630_x x3
	local rr630_y infant_w
	local rr630_fe fe1
	local rr630_p p1
	
	*rr640
	local rr640_x x1
	local rr640_y log_thiamine_pcd_w
	local rr640_fe fe1
	local rr640_p p1
	
	*rr650
	local rr650_x x1
	local rr650_y thiamine_home_pcd_w
	local rr650_fe fe1
	local rr650_p p1
	
	*rr660
	local rr660_x x1
	local rr660_y thiamine_purchase_pcd_w
	local rr660_fe fe1
	local rr660_p p1
	
	*rr670
	local rr670_x x2
	local rr670_y thiamine_lt100p
	local rr670_fe fe1
	local rr670_p p1
	
	*rr680
	local rr680_x x2
	local rr680_y thiamine_lt80p
	local rr680_fe fe1
	local rr680_p p1

	*rr690
	local rr690_x x2
	local rr690_y thiamine_lt50p
	local rr690_fe fe1
	local rr690_p p1

	*rr700
	local rr700_x x1
	local rr700_y log_riboflavin_pcd_w
	local rr700_fe fe1
	local rr700_p p1

	*rr710
	local rr710_x x1
	local rr710_y riboflavin_home_pcd_w
	local rr710_fe fe1
	local rr710_p p1

	*rr720
	local rr720_x x1
	local rr720_y riboflavin_purchase_pcd_w
	local rr720_fe fe1
	local rr720_p p1

	*rr730
	local rr730_x x2
	local rr730_y riboflavin_lt100p
	local rr730_fe fe1
	local rr730_p p1

	*rr740
	local rr740_x x2
	local rr740_y riboflavin_lt80p
	local rr740_fe fe1
	local rr740_p p1

	*rr750
	local rr750_x x2
	local rr750_y riboflavin_lt50p
	local rr750_fe fe1
	local rr750_p p1

	*rr760
	local rr760_x x1
	local rr760_y log_niacin_pcd_w
	local rr760_fe fe1
	local rr760_p p1

	*rr770
	local rr770_x x1
	local rr770_y niacin_home_pcd_w
	local rr770_fe fe1
	local rr770_p p1

	*rr780
	local rr780_x x1
	local rr780_y niacin_purchase_pcd_w
	local rr780_fe fe1
	local rr780_p p1

	*rr790
	local rr790_x x2
	local rr790_y niacin_lt100p
	local rr790_fe fe1
	local rr790_p p1

	*rr800
	local rr800_x x2
	local rr800_y niacin_lt80p
	local rr800_fe fe1
	local rr800_p p1

	*rr810
	local rr810_x x2
	local rr810_y niacin_lt50p
	local rr810_fe fe1
	local rr810_p p1

	*rr820
	local rr820_x x1
	local rr820_y log_ascorbic_acid_pcd_w
	local rr820_fe fe1
	local rr820_p p1

	*rr830
	local rr830_x x1
	local rr830_y ascorbic_acid_home_pcd_w
	local rr830_fe fe1
	local rr830_p p1

	*rr840
	local rr840_x x1
	local rr840_y ascorbic_acid_purchase_pcd_w
	local rr840_fe fe1
	local rr840_p p1

	*rr850
	local rr850_x x2
	local rr850_y ascorbic_acid_lt100p
	local rr850_fe fe1
	local rr850_p p1

	*rr860
	local rr860_x x2
	local rr860_y ascorbic_acid_lt80p
	local rr860_fe fe1
	local rr860_p p1

	*rr870
	local rr870_x x2
	local rr870_y ascorbic_acid_lt50p
	local rr870_fe fe1
	local rr870_p p1
	
	*rr880
	local rr880_x x2
	local rr880_y zinc_lt60p
	local rr880_fe fe1
	local rr880_p p1
	
	*rr890
	local rr890_x x2
	local rr890_y protein_lt60p
	local rr890_fe fe1
	local rr890_p p1
	
	*rr900
	local rr900_x x2
	local rr900_y thiamine_lt60p
	local rr900_fe fe1
	local rr900_p p1
	
	*rr910
	local rr910_x x2
	local rr910_y riboflavin_lt60p
	local rr910_fe fe1
	local rr910_p p1
	
	*rr920
	local rr920_x x2
	local rr920_y niacin_lt60p
	local rr920_fe fe1
	local rr920_p p1
	
	*rr930
	local rr930_x x2
	local rr930_y ascorbic_acid_lt60p
	local rr930_fe fe1
	local rr930_p p1

	
	*define regressions
	*rr#1: district-month, & year-month fixed effects, state-year trend, demographic controls
	*this and last year's weather
	*rr11
	local rr11_x x1
	local rr11_y log_calories_pcd_w
	local rr11_fe fe2
	local rr11_p p1
	
	*rr21
	local rr21_x x1
	local rr21_y calories_home_pcd_w
	local rr21_fe fe2
	local rr21_p p1
	
	*rr31
	local rr31_x x1
	local rr31_y calories_purchase_pcd_w
	local rr31_fe fe2
	local rr31_p p1
	
	*rr41
	local rr41_x x1
	local rr41_y log_iron_pcd_w
	local rr41_fe fe2
	local rr41_p p1
	
	*rr51
	local rr51_x x2
	local rr51_y iron_lt50p
	local rr51_fe fe2
	local rr51_p p1
	
	*rr61
	local rr61_x x1
	local rr61_y iron_home_pcd_w
	local rr61_fe fe2
	local rr61_p p1
	
	*rr71
	local rr71_x x1
	local rr71_y iron_purchase_pcd_w
	local rr71_fe fe2
	local rr71_p p1
	
	*rr81
	local rr81_x x2
	local rr81_y calories_lt100p
	local rr81_fe fe2
	local rr81_p p1
	
	*rr91
	local rr91_x x2
	local rr91_y calories_lt80p
	local rr91_fe fe2
	local rr91_p p1
	
	*rr101
	local rr101_x x2
	local rr101_y iron_lt80p
	local rr101_fe fe2
	local rr101_p p1
	
	*rr111
	local rr111_x x2
	local rr111_y iron_lt100p
	local rr111_fe fe2
	local rr111_p p1
	
	*rr121
	local rr121_x x2
	local rr121_y calories_lt60p
	local rr121_fe fe2
	local rr121_p p1
	
	*rr131
	local rr131_x x2
	local rr131_y iron_lt60p
	local rr131_fe fe2
	local rr131_p p1
	
	*rr291
	local rr291_x x2
	local rr291_y protein_lt80p
	local rr291_fe fe2
	local rr291_p p1
	
	*rr301
	local rr301_x x2
	local rr301_y zinc_lt80p
	local rr301_fe fe2
	local rr301_p p1
	
	*rr681
	local rr681_x x2
	local rr681_y thiamine_lt80p
	local rr681_fe fe2
	local rr681_p p1
	
	*rr741
	local rr741_x x2
	local rr741_y riboflavin_lt80p
	local rr741_fe fe2
	local rr741_p p1
	
	*rr801
	local rr801_x x2
	local rr801_y niacin_lt80p
	local rr801_fe fe2
	local rr801_p p1
	
	*rr861
	local rr861_x x2
	local rr861_y ascorbic_acid_lt80p
	local rr861_fe fe2
	local rr861_p p1
	
	
	*define regressions
	*rr#2: district, month, & year fixed effects, state-year trend, demographic controls, rainfall
	*this and last year's weather
	*kids count as half an adult
	
	*rr12
	local rr12_x x1
	local rr12_y log_calories_pcd_kh_w
	local rr12_fe fe1
	local rr12_p p1
	
	*rr22
	local rr22_x x1
	local rr22_y calories_home_pcd_kh_w
	local rr22_fe fe1
	local rr22_p p1
	
	*rr32
	local rr32_x x1
	local rr32_y calories_purchase_pcd_kh_w
	local rr32_fe fe1
	local rr32_p p1
	
	*rr42
	local rr42_x x1
	local rr42_y log_iron_pcd_kh_w
	local rr42_fe fe1
	local rr42_p p1
	
	*rr62
	local rr62_x x1
	local rr62_y iron_home_pcd_kh_w
	local rr62_fe fe1
	local rr62_p p1
	
	*rr72
	local rr72_x x1
	local rr72_y iron_purchase_pcd_kh_w
	local rr72_fe fe1
	local rr72_p p1
	
	*define regressions
	*rr#3: district, month, & year fixed effects, state-year trend, demographic controls, rainfall
	*this and last year's weather
	*kids count as third an adult
	
	*rr13
	local rr13_x x1
	local rr13_y log_calories_pcd_kt_w
	local rr13_fe fe1
	local rr13_p p1
	
	*rr23
	local rr23_x x1
	local rr23_y calories_home_pcd_kt_w
	local rr23_fe fe1
	local rr23_p p1
	
	*rr33
	local rr33_x x1
	local rr33_y calories_purchase_pcd_kt_w
	local rr33_fe fe1
	local rr33_p p1
	
	*rr43
	local rr43_x x1
	local rr43_y log_iron_pcd_kt_w
	local rr43_fe fe1
	local rr43_p p1
	
	*rr63
	local rr63_x x1
	local rr63_y iron_home_pcd_kt_w
	local rr63_fe fe1
	local rr63_p p1
	
	*rr73
	local rr73_x x1
	local rr73_y iron_purchase_pcd_kt_w
	local rr73_fe fe1
	local rr73_p p1
	

	**********test different rainfall specifications***********
	*rr#4: district, month, & year fixed effects, state-year trend, demographic controls, total rainfall
	*this and last year's weather
	
	*rr14
	local rr14_x x1
	local rr14_y log_calories_pcd_w
	local rr14_fe fe1
	local rr14_p p4
	
	*rr24
	local rr24_x x1
	local rr24_y calories_home_pcd_w
	local rr24_fe fe1
	local rr24_p p4
	
	*rr34
	local rr34_x x1
	local rr34_y calories_purchase_pcd_w
	local rr34_fe fe1
	local rr34_p p4
	
	*rr44
	local rr44_x x1
	local rr44_y log_iron_pcd_w
	local rr44_fe fe1
	local rr44_p p4

	*rr54
	local rr54_x x2
	local rr54_y iron_lt50p
	local rr54_fe fe1
	local rr54_p p4
	
	*rr64
	local rr64_x x1
	local rr64_y iron_home_pcd_w
	local rr64_fe fe1
	local rr64_p p4
	
	*rr74
	local rr74_x x1
	local rr74_y iron_purchase_pcd_w
	local rr74_fe fe1
	local rr74_p p4
	
	*rr84
	local rr84_x x2
	local rr84_y calories_lt100p
	local rr84_fe fe1
	local rr84_p p4
	
	*rr94
	local rr94_x x2
	local rr94_y calories_lt80p
	local rr94_fe fe1
	local rr94_p p4
	
	*rr104
	local rr104_x x2
	local rr104_y iron_lt80p
	local rr104_fe fe1
	local rr104_p p4
	
	*rr114
	local rr114_x x2
	local rr114_y iron_lt100p
	local rr114_fe fe1
	local rr114_p p4
	
	*rr124
	local rr124_x x2
	local rr124_y calories_lt60p
	local rr124_fe fe1
	local rr124_p p4
	
	*rr134
	local rr134_x x2
	local rr134_y iron_lt60p
	local rr134_fe fe1
	local rr134_p p4
	
	*rr294
	local rr294_x x2
	local rr294_y protein_lt80p
	local rr294_fe fe1
	local rr294_p p4
	
	*rr304
	local rr304_x x2
	local rr304_y zinc_lt80p
	local rr304_fe fe1
	local rr304_p p4
	
	*rr684
	local rr684_x x2
	local rr684_y thiamine_lt80p
	local rr684_fe fe1
	local rr684_p p4
	
	*rr744
	local rr744_x x2
	local rr744_y riboflavin_lt80p
	local rr744_fe fe1
	local rr744_p p4
	
	*rr804
	local rr804_x x2
	local rr804_y niacin_lt80p
	local rr804_fe fe1
	local rr804_p p4
	
	*rr864
	local rr864_x x2
	local rr864_y ascorbic_acid_lt80p
	local rr864_fe fe1
	local rr864_p p4

	
	**********test different rainfall specifications***********
	*rr#5: district, month, & year fixed effects, state-year trend, demographic controls,
	*how dry and wet, this and last year's weather
	
	*rr15
	local rr15_x x1
	local rr15_y log_calories_pcd_w
	local rr15_fe fe1
	local rr15_p p5
	
	*rr25
	local rr25_x x1
	local rr25_y calories_home_pcd_w
	local rr25_fe fe1
	local rr25_p p5
	
	*rr35
	local rr35_x x1
	local rr35_y calories_purchase_pcd_w
	local rr35_fe fe1
	local rr35_p p5
	
	*rr45
	local rr45_x x1
	local rr45_y log_iron_pcd_w
	local rr45_fe fe1
	local rr45_p p5
	
	*rr55
	local rr55_x x2
	local rr55_y iron_lt50p
	local rr55_fe fe1
	local rr55_p p5
	
	*rr65
	local rr65_x x1
	local rr65_y iron_home_pcd_w
	local rr65_fe fe1
	local rr65_p p5
	
	*rr75
	local rr75_x x1
	local rr75_y iron_purchase_pcd_w
	local rr75_fe fe1
	local rr75_p p5
	
	*rr85
	local rr85_x x2
	local rr85_y calories_lt100p
	local rr85_fe fe1
	local rr85_p p5
	
	*rr95
	local rr95_x x2
	local rr95_y calories_lt80p
	local rr95_fe fe1
	local rr95_p p5
	
	*rr105
	local rr105_x x2
	local rr105_y iron_lt80p
	local rr105_fe fe1
	local rr105_p p5
	
	*rr115
	local rr115_x x2
	local rr115_y iron_lt100p
	local rr115_fe fe1
	local rr115_p p5
	
	*rr125
	local rr125_x x2
	local rr125_y calories_lt60p
	local rr125_fe fe1
	local rr125_p p5
	
	*rr135
	local rr135_x x2
	local rr135_y iron_lt60p
	local rr135_fe fe1
	local rr135_p p5
	
	*rr295
	local rr295_x x2
	local rr295_y protein_lt80p
	local rr295_fe fe1
	local rr295_p p5
	
	*rr305
	local rr305_x x2
	local rr305_y zinc_lt80p
	local rr305_fe fe1
	local rr305_p p5
	
	*rr685
	local rr685_x x2
	local rr685_y thiamine_lt80p
	local rr685_fe fe1
	local rr685_p p5
	
	*rr745
	local rr745_x x2
	local rr745_y riboflavin_lt80p
	local rr745_fe fe1
	local rr745_p p5
	
	*rr805
	local rr805_x x2
	local rr805_y niacin_lt80p
	local rr805_fe fe1
	local rr805_p p5
	
	*rr865
	local rr865_x x2
	local rr865_y ascorbic_acid_lt80p
	local rr865_fe fe1
	local rr865_p p5
	
	**********test different rainfall specifications***********
	*rr#6: district, month, & year fixed effects, state-year trend, demographic controls,
	*dry and wet shocks, this and last year's weather
	
	*rr16
	local rr16_x x1
	local rr16_y log_calories_pcd_w
	local rr16_fe fe1
	local rr16_p p6
	
	*rr26
	local rr26_x x1
	local rr26_y calories_home_pcd_w
	local rr26_fe fe1
	local rr26_p p6
	
	*rr36
	local rr36_x x1
	local rr36_y calories_purchase_pcd_w
	local rr36_fe fe1
	local rr36_p p6
	
	*rr46
	local rr46_x x1
	local rr46_y log_iron_pcd_w
	local rr46_fe fe1
	local rr46_p p6
	
	*rr56
	local rr56_x x2
	local rr56_y iron_lt50p
	local rr56_fe fe1
	local rr56_p p6
	
	*rr66
	local rr66_x x1
	local rr66_y iron_home_pcd_w
	local rr66_fe fe1
	local rr66_p p6
	
	*rr76
	local rr76_x x1
	local rr76_y iron_purchase_pcd_w
	local rr76_fe fe1
	local rr76_p p6
	
	*rr86
	local rr86_x x2
	local rr86_y calories_lt100p
	local rr86_fe fe1
	local rr86_p p6
	
	*rr96
	local rr96_x x2
	local rr96_y calories_lt80p
	local rr96_fe fe1
	local rr96_p p6
	
	*rr106
	local rr106_x x2
	local rr106_y iron_lt80p
	local rr106_fe fe1
	local rr106_p p6
	
	*rr116
	local rr116_x x2
	local rr116_y iron_lt100p
	local rr116_fe fe1
	local rr116_p p6
	
	*rr126
	local rr126_x x2
	local rr126_y calories_lt60p
	local rr126_fe fe1
	local rr126_p p6
	
	*rr136
	local rr136_x x2
	local rr136_y iron_lt60p
	local rr136_fe fe1
	local rr136_p p6
	
	*rr296
	local rr296_x x2
	local rr296_y protein_lt80p
	local rr296_fe fe1
	local rr296_p p6
	
	*rr306
	local rr306_x x2
	local rr306_y zinc_lt80p
	local rr306_fe fe1
	local rr306_p p6
	
	*rr686
	local rr686_x x2
	local rr686_y thiamine_lt80p
	local rr686_fe fe1
	local rr686_p p6
	
	*rr746
	local rr746_x x2
	local rr746_y riboflavin_lt80p
	local rr746_fe fe1
	local rr746_p p6
	
	*rr806
	local rr806_x x2
	local rr806_y niacin_lt80p
	local rr806_fe fe1
	local rr806_p p6
	
	*rr866
	local rr866_x x2
	local rr866_y ascorbic_acid_lt80p
	local rr866_fe fe1
	local rr866_p p6
	
	*define regressions 
	*rr#7: district, month, & year fixed effects, state-year quadratic trend, demographic controls, rainfall
	*all weather 
	*rr17
	local rr17_x x1
	local rr17_y log_calories_pcd_w
	local rr17_fe fe5
	local rr17_p p1
	
	*rr87
	local rr87_x x2
	local rr87_y calories_lt100p
	local rr87_fe fe5
	local rr87_p p1
	
	*rr97
	local rr97_x x2
	local rr97_y calories_lt80p
	local rr97_fe fe5
	local rr97_p p1
	
	*rr107
	local rr107_x x2
	local rr107_y iron_lt80p
	local rr107_fe fe5
	local rr107_p p1
	
	*rr117
	local rr117_x x2
	local rr117_y iron_lt100p
	local rr117_fe fe5
	local rr117_p p1
	
	*rr127
	local rr127_x x2
	local rr127_y calories_lt60p
	local rr127_fe fe5
	local rr127_p p1
	
	*rr297
	local rr297_x x2
	local rr297_y protein_lt80p
	local rr297_fe fe5
	local rr297_p p1
	
	*rr307
	local rr307_x x2
	local rr307_y zinc_lt80p
	local rr307_fe fe5
	local rr307_p p1
	
	*rr687
	local rr687_x x2
	local rr687_y thiamine_lt80p
	local rr687_fe fe5
	local rr687_p p1
	
	*rr747
	local rr747_x x2
	local rr747_y riboflavin_lt80p
	local rr747_fe fe5
	local rr747_p p1
	
	*rr807
	local rr807_x x2
	local rr807_y niacin_lt80p
	local rr807_fe fe5
	local rr807_p p1
	
	
	*define regressions
	*rr#8: district, month, & year fixed effects, state-year trend, demographic controls, rainfall
	*just last year's weather
	
	*rr18
	local rr18_x x5
	local rr18_y log_calories_pcd_w
	local rr18_fe fe1
	local rr18_p p2
	
	*rr28
	local rr28_x x5
	local rr28_y calories_home_pcd_w
	local rr28_fe fe1
	local rr28_p p2
	
	*rr38
	local rr38_x x5
	local rr38_y calories_purchase_pcd_w
	local rr38_fe fe1
	local rr38_p p2
	
	*rr48
	local rr48_x x5
	local rr48_y log_iron_pcd_w
	local rr48_fe fe1
	local rr48_p p2
	
	*rr58
	local rr58_x x7
	local rr58_y iron_lt50p
	local rr58_fe fe1
	local rr58_p p2
	
	*rr68
	local rr68_x x5
	local rr68_y iron_home_pcd_w
	local rr68_fe fe1
	local rr68_p p2
	
	*rr78
	local rr78_x x5
	local rr78_y iron_purchase_pcd_w
	local rr78_fe fe1
	local rr78_p p2
	
	*rr88
	local rr88_x x7
	local rr88_y calories_lt100p
	local rr88_fe fe1
	local rr88_p p2
	
	*rr98
	local rr98_x x7
	local rr98_y calories_lt80p
	local rr98_fe fe1
	local rr98_p p2
	
	*rr108
	local rr108_x x7
	local rr108_y iron_lt80p
	local rr108_fe fe1
	local rr108_p p2
	
	*rr118
	local rr118_x x7
	local rr118_y iron_lt100p
	local rr118_fe fe1
	local rr118_p p2
	
	
	*rr128
	local rr128_x x7
	local rr128_y calories_lt60p
	local rr128_fe fe1
	local rr128_p p2
	
	*rr138
	local rr138_x x7
	local rr138_y iron_lt60p
	local rr138_fe fe1
	local rr138_p p2
	
	*rr298
	local rr298_x x7
	local rr298_y protein_lt80p
	local rr298_fe fe1
	local rr298_p p2
	
	*rr308
	local rr308_x x7
	local rr308_y zinc_lt80p
	local rr308_fe fe1
	local rr308_p p2
	
	*rr688
	local rr688_x x7
	local rr688_y thiamine_lt80p
	local rr688_fe fe1
	local rr688_p p2
	
	*rr748
	local rr748_x x7
	local rr748_y riboflavin_lt80p
	local rr748_fe fe1
	local rr748_p p2
	
	*rr808
	local rr808_x x7
	local rr808_y niacin_lt80p
	local rr808_fe fe1
	local rr808_p p2
	
	*rr868
	local rr868_x x7
	local rr868_y ascorbic_acid_lt80p
	local rr868_fe fe1
	local rr868_p p2
	
	
	
	*define regressions
	*rr#9: district, month, & year fixed effects, district-year trend, demographic controls, rainfall
	*this and last year's weather
	
	*rr19
	local rr19_x x1
	local rr19_y log_calories_pcd_w
	local rr19_fe fe4
	local rr19_p p1
	
	
	*rr29
	local rr29_x x1
	local rr29_y calories_home_pcd_w
	local rr29_fe fe4
	local rr29_p p1
	
	*rr39
	local rr39_x x1
	local rr39_y calories_purchase_pcd_w
	local rr39_fe fe4
	local rr39_p p1
	
	*rr49
	local rr49_x x1
	local rr49_y log_iron_pcd_w
	local rr49_fe fe4
	local rr49_p p1
	
	*rr59
	local rr59_x x2
	local rr59_y iron_lt50p
	local rr59_fe fe4
	local rr59_p p1
	
	*rr69
	local rr69_x x1
	local rr69_y iron_home_pcd_w
	local rr69_fe fe4
	local rr69_p p1
	
	*rr79
	local rr79_x x1
	local rr79_y iron_purchase_pcd_w
	local rr79_fe fe4
	local rr79_p p1
	
	*rr89
	local rr89_x x2
	local rr89_y calories_lt100p
	local rr89_fe fe4
	local rr89_p p1
	
	*rr99
	local rr99_x x2
	local rr99_y calories_lt80p
	local rr99_fe fe4
	local rr99_p p1
	
	*rr109
	local rr109_x x2
	local rr109_y iron_lt80p
	local rr109_fe fe4
	local rr109_p p1
	
	*rr119
	local rr119_x x2
	local rr119_y iron_lt100p
	local rr119_fe fe4
	local rr119_p p1
	
	*rr129
	local rr129_x x2
	local rr129_y calories_lt60p
	local rr129_fe fe4
	local rr129_p p1
	
	
	*rr299
	local rr299_x x2
	local rr299_y protein_lt80p
	local rr299_fe fe4
	local rr299_p p1
	
	*rr309
	local rr309_x x2
	local rr309_y zinc_lt80p
	local rr309_fe fe4
	local rr309_p p1
	
	*rr689
	local rr689_x x2
	local rr689_y thiamine_lt80p
	local rr689_fe fe4
	local rr689_p p1
	
	*rr749
	local rr749_x x2
	local rr749_y riboflavin_lt80p
	local rr749_fe fe4
	local rr749_p p1
	
	*rr809
	local rr809_x x2
	local rr809_y niacin_lt80p
	local rr809_fe fe4
	local rr809_p p1
	
	*rr869
	local rr869_x x2
	local rr869_y ascorbic_acid_lt80p
	local rr869_fe fe4
	local rr869_p p1
	
	
	cd `output'
	foreach run in `reglist'{
		cap log close
		log using /Users/paulstainier/Dropbox/1_rii/4_analysis/output/log/log_regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster.txt, text replace
		reghdfe ``run'_y' ```run'_x'' ```run'_p''  , absorb(```run'_fe'') vce(cluster distid3)  noconstant
		estimates save regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster, replace
		outreg2 using regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster.txt, replace
		log close
	}	
	*get table nums
	foreach run in `reglist'{
		cd `output'
		estimates use regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster
		insheet using regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster.txt, clear
		local est_num = 4
		egen stars = sieve(v2), char(*)

		cd `table_coef_path'
		local coeflist ```run'_x'' ```run'_p''

		foreach coefname in `coeflist'{
			gen coef_`coefname' = _b[`coefname']
			gen std_`coefname' = _se[`coefname']
			format coef_`coefname'  std_`coefname' %9.3fc
			tostring coef_`coefname'  std_`coefname', replace force usedisplayformat
			export delim coef_`coefname' using "`run'_coef_`coefname'.txt"  if _n == `est_num', novarnames replace
			export delim stars using "`run'_star_`coefname'.txt"  if _n == `est_num', novarnames replace
			export delim std_`coefname' using  "`run'_std_`coefname'.txt"  if _n == `est_num', novarnames replace
			local est_num = `est_num' + 2
		}
		gen num_obs = e(N)
		format num_obs %9.0fc
		tostring num_obs, replace force usedisplayformat
		export delim num_obs using "`run'_``run'_y'_numobs.txt"  if _n == 1, novarnames replace delimiter(" ")
	}
}


***************************
*
*RUN_REGHDFE_FIRSTDIFF
*
*first difference regressions
*
***************************
if "`run_reghdfe_firstdiff'" == "yes"{
	local reglist
	foreach num of numlist  10 80 90 100 120 290 300 680 740 800{
		local reglist `reglist' rfd`num'
	}
	
	cd `input'
	use nss_nutrition_era5_weather_2003_2012_all_analysis, clear
	
	*drop observations missing variables that are in every specification
	foreach var in teenage_boy_w child_boy_w infant_boy_w teenage_girl_w child_girl_w infant_girl_w adult_man_w adult_woman_w house_size_w distid3 year month year state religion social_group head_educ{
		drop if missing(`var')
	}
		
	**************
	*collapse to district year level 
	**************
	local weather_vars
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local weather_vars `weather_vars' zeros`time_name' tmax_70_80`time_name'  tmax_80_90`time_name' tmax_90_100`time_name' tmax_100_110`time_name' tmax_gt110`time_name' rain_shock`time_name' 
	}
	
	local nutrition_vars log_calories_pcd_w calories_lt100p calories_lt80p iron_lt80p  calories_lt60p protein_lt80p zinc_lt80p thiamine_lt80p riboflavin_lt80p niacin_lt80p
	
	gen num_households = 1
	
	collapse (mean) `weather_vars' `nutrition_vars' (sum) num_households, by(distid3 year state)
	
	
	
	**************
	*create first difference variables
	**************
	sort distid3 year 
	foreach var in `weather_vars' `nutrition_vars'{
		by distid3 (year): gen `var'_d = .
		by distid3 (year): replace `var'_d = `var' - `var'[_n-1] if year == year[_n-1] + 1
	}
	
	drop if year == 2003
	bys distid3: egen total_households = total(num_households)
	
	**************
	*define regressions
	**************
	*x1
	local x1 
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local x1 `x1'  zeros`time_name'_d tmax_70_80`time_name'_d  tmax_80_90`time_name'_d tmax_90_100`time_name'_d tmax_100_110`time_name'_d tmax_gt110`time_name'_d  
	}
	
	*p1
	local p1
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local p1 `p1' rain_shock`time_name'_d   
	}
	gen year2 = year - 2002
	label var year2 "Year with 2003 = 1"
	
	*fe1 
	local fe1 year state
	
	
	*rfd10
	local rfd10_x x1
	local rfd10_y log_calories_pcd_w_d
	local rfd10_fe fe1
	local rfd10_p p1
	
	*rfd80
	local rfd80_x x1
	local rfd80_y calories_lt100p_d
	local rfd80_fe fe1
	local rfd80_p p1
	
	*rfd90
	local rfd90_x x1
	local rfd90_y calories_lt80p_d
	local rfd90_fe fe1
	local rfd90_p p1
	
	*rfd100
	local rfd100_x x1
	local rfd100_y iron_lt80p_d
	local rfd100_fe fe1
	local rfd100_p p1
	
	*rfd120
	local rfd120_x x1
	local rfd120_y calories_lt60p_d
	local rfd120_fe fe1
	local rfd120_p p1
	
	*rfd290
	local rfd290_x x1
	local rfd290_y protein_lt80p_d
	local rfd290_fe fe1
	local rfd290_p p1
	
	*rfd300
	local rfd300_x x1
	local rfd300_y zinc_lt80p_d
	local rfd300_fe fe1
	local rfd300_p p1
	
	*rfd680
	local rfd680_x x1
	local rfd680_y thiamine_lt80p_d
	local rfd680_fe fe1
	local rfd680_p p1

	*rfd740
	local rfd740_x x1
	local rfd740_y riboflavin_lt80p_d
	local rfd740_fe fe1
	local rfd740_p p1

	*rfd800
	local rfd800_x x1
	local rfd800_y niacin_lt80p_d
	local rfd800_fe fe1
	local rfd800_p p1
	
	**************
	*run regressions
	**************
	cd `output'
	foreach run in `reglist'{
		cap log close
		log using /Users/paulstainier/Dropbox/1_rii/4_analysis/output/log/log_regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_statecluster_hhwgt.txt, text replace
		reghdfe ``run'_y' ```run'_x'' ```run'_p''  [fw = total_households], absorb(```run'_fe'') vce(cluster state)  noconstant
		estimates save regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_statecluster_hhwgt, replace
		outreg2 using regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_statecluster_hhwgt.txt, replace
		reghdfe ``run'_y' ```run'_x'' ```run'_p'' , absorb(```run'_fe'') vce(cluster state)  noconstant
		estimates save regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_statecluster_nowgt, replace
		log close
	}	
	*get table nums
	foreach run in `reglist'{
		cd `output'
		estimates use regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_statecluster_hhwgt
		insheet using regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_statecluster_hhwgt.txt, clear
		local est_num = 4
		egen stars = sieve(v2), char(*)

		cd `table_coef_path'
		local coeflist ```run'_x'' ```run'_p''

		foreach coefname in `coeflist'{
			gen coef_`coefname' = _b[`coefname']
			gen std_`coefname' = _se[`coefname']
			format coef_`coefname'  std_`coefname' %9.3fc
			tostring coef_`coefname'  std_`coefname', replace force usedisplayformat
			export delim coef_`coefname' using "`run'_coef_`coefname'.txt"  if _n == `est_num', novarnames replace
			export delim stars using "`run'_star_`coefname'.txt"  if _n == `est_num', novarnames replace
			export delim std_`coefname' using  "`run'_std_`coefname'.txt"  if _n == `est_num', novarnames replace
			local est_num = `est_num' + 2
		}
		cd `output'
		estimates use regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_statecluster_nowgt
		cd `table_coef_path'
		gen num_obs = e(N)
		format num_obs %9.0fc
		tostring num_obs, replace force usedisplayformat
		export delim num_obs using "`run'_``run'_y'_numobs.txt"  if _n == 1, novarnames replace delimiter(" ")
	}

	
}



***************************
*
*RUN_REGHDFE_THRESHOLDS
*
*run regressions for 
*different thresholds
*of calorie and nutrient
*consumption 
*
***************************
if "`run_reghdfe_thresholds'" == "yes"{
	*decide which regressions to run and add them to the list 

	
	local reglist
	foreach num of numlist  50(10)150{
		local reglist `reglist' rrc`num' 		
		local reglist `reglist' rri`num' 		
		local reglist `reglist' rrp`num' 		
		local reglist `reglist' rrz`num' 		
		local reglist `reglist' rrt`num' 		
		local reglist `reglist' rrr`num' 		
		local reglist `reglist' rrn`num' 
		local reglist `reglist' rra`num' 
	}
	
	cd `input'
	use nss_nutrition_era5_weather_2003_2012_all_analysis, clear
	
	*drop observations missing variables that are in every specification
	foreach var in teenage_boy_w child_boy_w infant_boy_w teenage_girl_w child_girl_w infant_girl_w adult_man_w adult_woman_w house_size_w distid3 year month year state religion social_group head_educ{
		drop if missing(`var')
	}
	
	
	*new temperature bins 
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		gen tmax_70_90`time_name' = tmax_70_80`time_name'+tmax_80_90`time_name' 
		gen tmax_90_110`time_name' = tmax_90_100`time_name' + tmax_100_110`time_name' 
	}
	

	
	*list of independent variables 
	
	*x2
	local x2 house_size_w
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local x2 `x2'  zeros`time_name' tmax_70_80`time_name'  tmax_80_90`time_name' tmax_90_100`time_name' tmax_100_110`time_name' tmax_gt110`time_name'
	}
	
	*fixed effects c.year2##i.state
	*fe1 
	local fe1 distid3 year month c.year2#i.state religion social_group head_educ 
	
	
	

	*precipitation variables
	*p1
	local p1
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local p1 `p1' rain_shock`time_name' 
	}
	
	
	
	*define regressions
	*rtcXX: calories threshold 
	*rtiXX: iron threshold
	*rr#0: district, month, & year fixed effects, state-year trend, demographic controls, rainfall
	*this and last year's weather
	
	foreach num of numlist 50(10)150{
		*calories regression
		local rrc`num'_x x2
		local rrc`num'_y calories_lt`num'p
		local rrc`num'_fe fe1
		local rrc`num'_p p1
		
		*iron regression
		local rri`num'_x x2
		local rri`num'_y iron_lt`num'p
		local rri`num'_fe fe1
		local rri`num'_p p1
		
		*protein regression
		local rrp`num'_x x2
		local rrp`num'_y protein_lt`num'p
		local rrp`num'_fe fe1
		local rrp`num'_p p1
		
		*zinc regression
		local rrz`num'_x x2
		local rrz`num'_y zinc_lt`num'p
		local rrz`num'_fe fe1
		local rrz`num'_p p1
		
		*thiamine regression
		local rrt`num'_x x2
		local rrt`num'_y thiamine_lt`num'p
		local rrt`num'_fe fe1
		local rrt`num'_p p1

		*riboflavin regression
		local rrr`num'_x x2
		local rrr`num'_y riboflavin_lt`num'p
		local rrr`num'_fe fe1
		local rrr`num'_p p1

		*niacin regression
		local rrn`num'_x x2
		local rrn`num'_y niacin_lt`num'p
		local rrn`num'_fe fe1
		local rrn`num'_p p1

		*ascorbic_acid regression
		local rra`num'_x x2
		local rra`num'_y ascorbic_acid_lt`num'p
		local rra`num'_fe fe1
		local rra`num'_p p1

	}
	
	
	
	cd `output'
	foreach run in `reglist'{
		cap log close
		log using /Users/paulstainier/Dropbox/1_rii/4_analysis/output/log/log_regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster.txt, text replace
		reghdfe ``run'_y' ```run'_x'' ```run'_p''  , absorb(```run'_fe'') vce(cluster distid3)  noconstant
		estimates save regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster, replace
		outreg2 using regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster.txt, replace
		log close
	}	
	
	*get table nums
	foreach run in `reglist'{
		cd `output'
		estimates use regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster
		insheet using regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster.txt, clear
		local est_num = 4
		egen stars = sieve(v2), char(*)

		cd `table_coef_path'
		local coeflist ```run'_x'' ```run'_p''

		foreach coefname in `coeflist'{
			gen coef_`coefname' = _b[`coefname']
			gen std_`coefname' = _se[`coefname']
			format coef_`coefname'  std_`coefname' %9.3fc
			tostring coef_`coefname'  std_`coefname', replace force usedisplayformat
			export delim coef_`coefname' using "`run'_coef_`coefname'.txt"  if _n == `est_num', novarnames replace
			export delim stars using "`run'_star_`coefname'.txt"  if _n == `est_num', novarnames replace
			export delim std_`coefname' using  "`run'_std_`coefname'.txt"  if _n == `est_num', novarnames replace
			local est_num = `est_num' + 2
		}
		gen num_obs = e(N)
		format num_obs %9.0fc
		tostring num_obs, replace force usedisplayformat
		export delim num_obs using "`run'_``run'_y'_numobs.txt"  if _n == 1, novarnames replace delimiter(" ")
	}
}




***************************
*
*RUN_REGHDFE_s10
*
*run regressions for 
*schedule 10 outcomes
*(time allocation)
*
***************************
if "`run_reghdfe_s10'" == "yes"{
	*decide which regressions to run and add them to the list 
	foreach num of numlist 10(10)170{
		local reglist `reglist' r10_`num'
		
	}
	
	cd `input'
	use nss10_employment_era5_weather_2004_2012_analysis, clear
	duplicates drop	
	*keep if round <= 64
	
	*list of independent variables 

	*x8
	local x8
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local x8 `x8'  zeros`time_name' tmax_70_80`time_name'  tmax_80_90`time_name' tmax_90_100`time_name' tmax_100_110`time_name' tmax_gt110`time_name' 
	}
	*precipitation variables
	*p1
	local p1
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local p1 `p1' rain_shock`time_name' 
	}
	
	*p2
	local p2
	foreach time_name in last_yall this_yall{
		local p2 `p2' rain_shock`time_name' 
	}
	
	
	*fixed effects
	*fe1 
	local fe1 distid3 year month c.year2#i.state religion social_group age sex educ_gen_cat
	
	*fe2
	local fe2 distid3 year month c.year2#i.state religion social_group age sex
	
	*define regressions
	*r10_10
	local r10_10_x x8
	local r10_10_y working_principal
	local r10_10_fe fe1
	local r10_10_p p1
	local r10_10_cond work_age
	
	*r10_20
	local r10_20_x x8
	local r10_20_y manuf_principal
	local r10_20_fe fe1
	local r10_20_p p1
	local r10_20_cond work_age
	
	*r10_30
	local r10_30_x x8
	local r10_30_y const_principal
	local r10_30_fe fe1
	local r10_30_p p1
	local r10_30_cond work_age
	
	*r10_40
	local r10_40_x x8
	local r10_40_y ag_principal
	local r10_40_fe fe1
	local r10_40_p p1
	local r10_40_cond work_age
	
	*r10_50
	local r10_50_x x8
	local r10_50_y unempl_principal
	local r10_50_fe fe1
	local r10_50_p p1
	local r10_50_cond work_age
	
	*r10_60
	local r10_60_x x8
	local r10_60_y domestic_duties_principal
	local r10_60_fe fe1
	local r10_60_p p1
	local r10_60_cond work_age
	
	*r10_70
	local r10_70_x x8
	local r10_70_y in_school_principal
	local r10_70_fe fe2
	local r10_70_p p1
	local r10_70_cond school_age
	
	*r10_80
	local r10_80_x x8
	local r10_80_y working_principal
	local r10_80_fe fe2
	local r10_80_p p1
	local r10_80_cond school_age
	
	*r10_90
	local r10_90_x x8
	local r10_90_y nonag_occ_principal
	local r10_90_fe fe1
	local r10_90_p p1
	local r10_90_cond work_age
	
	*r10_100
	local r10_100_x x8
	local r10_100_y ag_principal
	local r10_100_fe fe2
	local r10_100_p p1
	local r10_100_cond school_age
	
	*r10_110
	local r10_110_x x8
	local r10_110_y nonag_occ_principal
	local r10_110_fe fe1
	local r10_110_p p1
	local r10_110_cond school_age
	
	*r10_120
	local r10_120_x x8
	local r10_120_y ag_at_home_principal
	local r10_120_fe fe1
	local r10_120_p p1
	local r10_120_cond work_age
	
	*r10_130
	local r10_130_x x8
	local r10_130_y ag_away_principal
	local r10_130_fe fe1
	local r10_130_p p1
	local r10_130_cond work_age
	
	*r10_140
	local r10_140_x x8
	local r10_140_y nonag_at_home_principal
	local r10_140_fe fe1
	local r10_140_p p1
	local r10_140_cond work_age
	
	*r10_150
	local r10_150_x x8
	local r10_150_y nonag_away_principal
	local r10_150_fe fe1
	local r10_150_p p1
	local r10_150_cond work_age
	
	*r10_160
	local r10_160_x x8
	local r10_160_y working_at_home_principal
	local r10_160_fe fe1
	local r10_160_p p1
	local r10_160_cond work_age
	
	*r10_170
	local r10_170_x x8
	local r10_170_y working_away_principal
	local r10_170_fe fe1
	local r10_170_p p1
	local r10_170_cond work_age
	
	
	
	
	
	cd `output'
	
	foreach run in `reglist'{
		cap log close
		log using /Users/paulstainier/Dropbox/1_rii/4_analysis/output/log/log_regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster.txt, text replace
		reghdfe ``run'_y' ```run'_x'' ```run'_p'' if ``run'_cond' == 1, absorb(```run'_fe'') vce(cluster distid3) 
		estimates save regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_distcluster_``run'_cond', replace
		outreg2 using regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_distcluster_``run'_cond'.txt, replace
		log close
	}
	
	*get table nums
	foreach run in `reglist'{
		cd `output'
		estimates use regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_distcluster_``run'_cond'
		insheet using regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_distcluster_``run'_cond'.txt, clear
		local est_num = 4
		egen stars = sieve(v2), char(*)

		cd `table_coef_path'
		local coeflist ```run'_x'' ```run'_p''

		foreach coefname in `coeflist'{
			gen coef_`coefname' = _b[`coefname']
			gen std_`coefname' = _se[`coefname']
			format coef_`coefname'  std_`coefname' %9.3fc
			tostring coef_`coefname'  std_`coefname', replace force usedisplayformat
			export delim coef_`coefname' using "`run'_coef_`coefname'.txt"  if _n == `est_num', novarnames replace
			export delim stars using "`run'_star_`coefname'.txt"  if _n == `est_num', novarnames replace
			export delim std_`coefname' using  "`run'_std_`coefname'.txt"  if _n == `est_num', novarnames replace
			local est_num = `est_num' + 2
		}
		gen num_obs = e(N)
		format num_obs %9.0fc
		tostring num_obs, replace force usedisplayformat
		export delim num_obs using "`run'_``run'_y'_numobs.txt"  if _n == 1, novarnames replace delimiter(" ")
	}
}



***************************
*
*run_reghdfe_icrisat
*
*run regressions for icrisat yield 
*
***************************
if "`run_reghdfe_icrisat'" == "yes"{
	*decide which regressions to run and add them to the list 
	local reglist
	foreach num of numlist 1(1)2{
		local reglist `reglist' r`num'
	}
	cd `input'
	
	insheet using icrisat_yield_era5_weather_1981_2011_analysis.csv, clear		
	keep if year >= 2000
	
	gen all = 1

	*gen district month fixed effects 
	destring lyield lyield_m, replace force
	
	*prec like manisha
	foreach grow_index in grow nogrow all{
		gen rain_shockthis_y`grow_index' = wetthis_y`grow_index' - drythis_y`grow_index'
	}
	
	*make tmax_gt90
	foreach time_name in this_ygrow this_ynogrow this_yall{
		gen tmax_gt100`time_name' =  tmax_100_110`time_name'+tmax_gt110`time_name' 
		gen tmax_gt90`time_name' =  tmax_90_100`time_name'+tmax_gt100`time_name' 
		gen tmax_lt60`time_name' =  tmax_lt50`time_name'+ tmax_50_60`time_name'
		gen zeros`time_name' = 0
	}
	
	foreach time_name in this_ygrow this_ynogrow{ 
		gen k_mdry`time_name' = kdry`time_name' - dry`time_name'
		gen m_vdry`time_name' = dry`time_name' - vdry`time_name'
		gen k_mwet`time_name' = kwet`time_name' - wet`time_name'
		gen m_vwet`time_name' = wet`time_name' - vwet`time_name'
	}
	
	*list of independent variables 
	*x1
	local x1 
	foreach time_name in this_ygrow this_ynogrow{
		local x1 `x1'  zeros`time_name' tmax_70_80`time_name'  tmax_80_90`time_name' tmax_90_100`time_name' tmax_100_110`time_name' tmax_gt110`time_name' 
	}
	
	local x2
	foreach time_name in this_yall{
		local x2 `x2'  zeros`time_name' tmax_70_80`time_name'  tmax_80_90`time_name tmax_90_100`time_name' tmax_100_110`time_name' tmax_gt110`time_name' 
	}
	
	
	
	
	*make log yield * 100 so it's in percentages
	replace lyield = lyield * 100
	replace lyield_m = lyield_m * 100
	
	*fixed effects
	*fe1
	local fe1 icrisat_district year 
	
	
	
	*precipitation variables
	*p1
	local p1
	foreach time_name in this_ygrow this_ynogrow{
		local p1 `p1' dry`time_name' wet`time_name'
	}
	
	local p2
	foreach time_name in this_ygrow this_ynogrow{
		local p2 `p2' rain_shock`time_name' 
	}
	
	local p3
	foreach time_name in this_ygrow this_ynogrow{
		local p3 `p3' k_mdry`time_name' m_vdry`time_name' vdry`time_name' k_mwet`time_name'  m_vwet`time_name' vwet`time_name'  
	}
	
	
	
	
	*define regressions
	*r1
	local r1_x x1
	local r1_y lyield
	local r1_fe fe1
	local r1_p p2
	
	*r2
	local r2_x x1 
	local r2_y lyield_m
	local r2_fe fe1
	local r2_p p2
	
	cd `output'
	foreach run in `reglist'{
		foreach sample in all{
			cap log close
			log using /Users/paulstainier/Dropbox/1_rii/4_analysis/output/log/log_regols_icrisat_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2000_2011_distcluster_`sample'.txt, text replace
			reghdfe ``run'_y' ```run'_x'' ```run'_p'' if `sample' == 1, absorb(```run'_fe'') vce(cluster icrisat_district) nocons 
			estimates save regols_icrisat_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2000_2011_distcluster_`sample', replace
			outreg2 using regols_icrisat_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2000_2011_distcluster_`sample'.txt, replace
			log close
			
		}
	}
	foreach run in `reglist'{
		foreach sample in all{
			
			*all
			cd `output'
			estimates use regols_icrisat_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2000_2011_distcluster_`sample'
			insheet using regols_icrisat_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2000_2011_distcluster_`sample'.txt, clear
			local est_num = 4
			egen stars = sieve(v2), char(*)

			cd `table_coef_path'
			local coeflist ```run'_x'' ```run'_p''

			foreach coefname in `coeflist'{
				gen coef_`coefname' = _b[`coefname']
				gen std_`coefname' = _se[`coefname']
				format coef_`coefname'  std_`coefname' %9.3fc
				tostring coef_`coefname'  std_`coefname', replace force usedisplayformat
				export delim coef_`coefname' using "`run'_icrisat_coef_`coefname'.txt"  if _n == `est_num', novarnames replace
				export delim stars using "`run'_icrisat_star_`coefname'.txt"  if _n == `est_num', novarnames replace
				export delim std_`coefname' using  "`run'_icrisat_std_`coefname'.txt"  if _n == `est_num', novarnames replace
				local est_num = `est_num' + 2
			}
			gen num_obs = e(N)
			format num_obs %9.0fc
			tostring num_obs, replace force usedisplayformat
			export delim num_obs using "`run'_icrisat_``run'_y'_numobs.txt"  if _n == 1, novarnames replace delimiter(" ")
			
		}
	}
}



***************************
*
*run_reghdfe_nfhs_by_age
*
*run regressions for nfhs mortality rate 
*by age group 
*
***************************
if "`run_reghdfe_nfhs_by_age'" == "yes"{
	*decide which regressions to run and add them to the list 
	
	local reglist
	foreach num of numlist 10(10)40 11(10)41{
		local reglist `reglist' r`num'	
	}
	cd `input'
	
	insheet using nfhs_mortality_by_age_era5_weather_2012_2020_analysis.csv, clear		
	gen log_death_rate_lt18_p1000 = log(death_rate_lt18_p1000)
	gen log_death_rate_18_39_p1000 = log(death_rate_18_39_p1000)
	gen log_death_rate_gte40_p1000 = log(death_rate_gte40_p1000)
	gen log_death_rate_gte60_p1000 = log(death_rate_gte60_p1000)

	winsor2 death_rate_lt18_p1000 death_rate_18_39_p1000 death_rate_gte40_p1000 death_rate_gte60_p1000 log*, cuts(1 99) suffix(_w)
	
	*prec like manisha
	foreach grow_index in grow nogrow all{
		gen rain_shockthis_y`grow_index' = wetthis_y`grow_index' - drythis_y`grow_index'
		gen rain_shocklast_y`grow_index' = wetlast_y`grow_index' - drylast_y`grow_index'
		gen zerosthis_y`grow_index' = 0 
		gen zeroslast_y`grow_index' = 0 
	}
	
	*create year measure with 2012 = 1 
	gen year2 = year - 2011
	
	*create state variable 
	encode statename4, gen(state_num)
	
	*list of independent variables 
	*x1
	local x1 
	foreach time_name in last_ygrow last_ynogrow this_ygrow this_ynogrow{
		local x1 `x1'  zeros`time_name'  tmax_70_80`time_name' tmax_80_90`time_name' tmax_90_100`time_name' tmax_100_110`time_name' tmax_gt110`time_name' 
	}
	
	local x2
	foreach time_name in last_yall this_yall{
		local x2 `x2'  zeros`time_name'  tmax_70_80`time_name' tmax_80_90`time_name' tmax_90_100`time_name' tmax_100_110`time_name' tmax_gt110`time_name' 
	}
	
	
	
	
	*fixed effects
	*fe1
	local fe1 district_n4 year 
	
	*fe2
	local fe2 district_n4 year c.year2#i.state_num
	
	*precipitation variables
	local p1
	foreach time_name in this_ygrow this_ynogrow last_ygrow last_ynogrow{
		local p1 `p1' rain_shock`time_name' 
	}
	
	local p2
	foreach time_name in this_yall last_yall{
		local p2 `p2' rain_shock`time_name' 
	}
	
	local p3
	foreach time_name in this_ygrow this_ynogrow{
		local p3 `p3' rain_shock`time_name' 
	}
	
	local p4
	foreach time_name in this_yall{
		local p4 `p4' rain_shock`time_name' 
	}
	
	
	*define regressions
	*rX0: district, year fixed effects, state-year trime trend, 
	*this and last year weather growing and non-growing
	*r10
	local r10_x x1
	local r10_y log_death_rate_lt18_p1000_w
	local r10_fe fe2
	local r10_p p1
	
	*r20
	local r20_x x1 
	local r20_y log_death_rate_18_39_p1000_w
	local r20_fe fe2
	local r20_p p1
	
	*r30
	local r30_x x1
	local r30_y log_death_rate_gte40_p1000_w
	local r30_fe fe2
	local r30_p p1
	
	*r40
	local r40_x x1 
	local r40_y log_death_rate_gte60_p1000_w
	local r40_fe fe2
	local r40_p p1
	
	
	*rX1: district, year fixed effects, state-year trime trend
	*this and last year weather all 
	*r11
	local r11_x x2
	local r11_y log_death_rate_lt18_p1000_w
	local r11_fe fe2
	local r11_p p2
	
	*r21
	local r21_x x2 
	local r21_y log_death_rate_18_39_p1000_w
	local r21_fe fe2
	local r21_p p2
	
	*r31
	local r31_x x2
	local r31_y log_death_rate_gte40_p1000_w
	local r31_fe fe2
	local r31_p p2
	
	*r41
	local r41_x x2 
	local r41_y log_death_rate_gte60_p1000_w
	local r41_fe fe2
	local r41_p p2
	
	
	cd `output'
	foreach run in `reglist'{

		cap log close
		log using /Users/paulstainier/Dropbox/1_rii/4_analysis/output/log/log_regols_nfhs_age_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2012_2019_distcluster.txt, text replace
		reghdfe ``run'_y' ```run'_x'' ```run'_p'' if year < 2020, absorb(```run'_fe'') vce(cluster district_n4) nocons 
		estimates save regols_nfhs_age_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2012_2019_distcluster, replace
		outreg2 using regols_nfhs_age_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2012_2019_distcluster.txt, replace
		log close

	}
	foreach run in `reglist'{
		cd `output'
		estimates use regols_nfhs_age_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2012_2019_distcluster
		insheet using regols_nfhs_age_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2012_2019_distcluster.txt, clear
		local est_num = 4
		egen stars = sieve(v2), char(*)

		cd `table_coef_path'
		local coeflist ```run'_x'' ```run'_p''

		foreach coefname in `coeflist'{
			gen coef_`coefname' = _b[`coefname']
			gen std_`coefname' = _se[`coefname']
			format coef_`coefname'  std_`coefname' %9.3fc
			tostring coef_`coefname'  std_`coefname', replace force usedisplayformat
			export delim coef_`coefname' using "`run'_nfhs_age_coef_`coefname'.txt"  if _n == `est_num', novarnames replace
			export delim stars using "`run'_nfhs_age_star_`coefname'.txt"  if _n == `est_num', novarnames replace
			export delim std_`coefname' using  "`run'_nfhs_age_std_`coefname'.txt"  if _n == `est_num', novarnames replace
			local est_num = `est_num' + 2
		}
		gen num_obs = e(N)
		format num_obs %9.0fc
		tostring num_obs, replace force usedisplayformat
		export delim num_obs using "`run'_nfhs_age_``run'_y'_numobs.txt"  if _n == 1, novarnames replace delimiter(" ")
			
	}
}



***************************
*
*plot_reghdfe_robust
*
*plot core regressions 
*
***************************
if "`plot_reghdfe_robust'" == "yes"{

	local plotlist
	foreach num of numlist 10(10)930{
		local plotlist `plotlist' rr`num'	
	}
	
	
	*rr#0: district, month, & year fixed effects, state-year trend, demographic controls, rainfall
	*this and last year's weather
	
	*rr10
	local rr10_x x1
	local rr10_y log_calories_pcd_w
	local rr10_fe fe1
	local rr10_p p1
	local rr10_l l1 
	local rr10_xtitle Temperature (F)
	local rr10_ytitle 100 x Log of Daily Calories Per Capita
	local rr10_yrange ylabel(-0.3(0.1)0.3, labsize(medlarge))
	local rr10_titlegap -88
	
	*rr20
	local rr20_x x1
	local rr20_y calories_home_pcd_w
	local rr20_fe fe1
	local rr20_p p1
	local rr20_l l1 
	local rr20_xtitle Temperature (F)
	local rr20_ytitle Daily Calories (kCal) Per Capita, Home-Grown
	local rr20_yrange ylabel(-10(2)10, labsize(medlarge))
	local rr20_titlegap -92
	
	*rr30
	local rr30_x x1
	local rr30_y calories_purchase_pcd_w
	local rr30_fe fe1
	local rr30_p p1
	local rr30_l l1 
	local rr30_xtitle Temperature (F)
	local rr30_ytitle Daily Calories (kCal) Per Capita, Purchased
	local rr30_yrange ylabel(-10(2)10, labsize(medlarge))
	local rr30_titlegap -87
	
	*rr40
	local rr40_x x1
	local rr40_y log_iron_pcd_w
	local rr40_fe fe1
	local rr40_p p1
	local rr40_l l1 
	local rr40_xtitle Temperature (F)
	local rr40_ytitle 100 x Log of Daily Iron Per Capita
	local rr40_yrange ylabel(-0.6(0.2)0.2, labsize(medlarge))
	local rr40_titlegap -80
	
	*rr50
	local rr50_x x2
	local rr50_y iron_lt50p
	local rr50_fe fe1
	local rr50_p p1
	local rr50_l l1 
	local rr50_xtitle Temperature (F)
	local rr50_ytitle Households below 50% Iron (%)
	local rr50_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr50_titlegap -65
	
	*rr60
	local rr60_x x1
	local rr60_y iron_home_pcd_w
	local rr60_fe fe1
	local rr60_p p1
	local rr60_l l1 
	local rr60_xtitle Temperature (F)
	local rr60_ytitle Daily Iron (mg) per Capita, Home-Grown 
	local rr60_yrange ylabel(-0.08(0.02)0.08, labsize(medlarge))
	local rr60_titlegap -90
	
	*rr70
	local rr70_x x1
	local rr70_y iron_purchase_pcd_w
	local rr70_fe fe1
	local rr70_p p1
	local rr70_l l1 
	local rr70_xtitle Temperature (F)
	local rr70_ytitle Daily Iron (mg) per Capita, Purchased
	local rr70_yrange ylabel(-0.08(0.02)0.08, labsize(medlarge))
	local rr70_titlegap -85
	
	*rr80
	local rr80_x x2
	local rr80_y calories_lt100p
	local rr80_fe fe1
	local rr80_p p1
	local rr80_l l1 
	local rr80_xtitle Temperature (F)
	local rr80_ytitle Households below 100% Calories (%)
	local rr80_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr80_titlegap -75
	
	*rr90
	local rr90_x x2
	local rr90_y calories_lt80p
	local rr90_fe fe1
	local rr90_p p1
	local rr90_l l1 
	local rr90_xtitle Temperature (F)
	local rr90_ytitle Households below 80% Calories (%)
	local rr90_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr90_titlegap -73
	
	*rr100
	local rr100_x x2
	local rr100_y iron_lt80p
	local rr100_fe fe1
	local rr100_p p1
	local rr100_l l1 
	local rr100_xtitle Temperature (F)
	local rr100_ytitle Households below 80% Iron (%)
	local rr100_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr100_titlegap -65
	
	*rr110
	local rr110_x x2
	local rr110_y iron_lt100p
	local rr110_fe fe1
	local rr110_p p1
	local rr110_l l1 
	local rr110_xtitle Temperature (F)
	local rr110_ytitle Households below 100% Iron (%)
	local rr110_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr110_titlegap -65
	
	*rr120
	local rr120_x x2
	local rr120_y calories_lt60p
	local rr120_fe fe1
	local rr120_p p1
	local rr120_l l1 
	local rr120_xtitle Temperature (F)
	local rr120_ytitle Households below 60% Calories (%)
	local rr120_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr120_titlegap -73
	
	*rr130
	local rr130_x x2
	local rr130_y iron_lt60p
	local rr130_fe fe1
	local rr130_p p1
	local rr130_l l1 
	local rr130_xtitle Temperature (F)
	local rr130_ytitle Households below 60% Iron (%)
	local rr130_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr130_titlegap -65

	
	*rr140
	local rr140_x x3
	local rr140_y num_kids_w
	local rr140_fe fe1
	local rr140_p p1
	local rr140_l l1 
	local rr140_xtitle Temperature (F)
	local rr140_ytitle Number of Children
	local rr140_yrange ylabel(-0.01(0.01)0.01, labsize(medlarge))
	local rr140_titlegap -43
	
	*rr150
	local rr150_x x3
	local rr150_y house_size_w
	local rr150_fe fe1
	local rr150_p p1
	local rr150_l l1 
	local rr150_xtitle Temperature (F)
	local rr150_ytitle House Size
	local rr150_yrange ylabel(-0.02(0.01)0.01, labsize(medlarge))
	local rr150_titlegap -30
	
	*rr160
	local rr160_x x3
	local rr160_y non_kids_house_size_w
	local rr160_fe fe1
	local rr160_p p1
	local rr160_l l1 
	local rr160_xtitle Temperature (F)
	local rr160_ytitle Number of Adults
	local rr160_yrange ylabel(-0.02(0.01)0.01, labsize(medlarge))
	local rr160_titlegap -37
	
	*rr170
	local rr170_x x3
	local rr170_y adult_lt30_w  
	local rr170_fe fe1
	local rr170_p p1
	local rr170_l l1 
	local rr170_xtitle Temperature (F)
	local rr170_ytitle Number of Adults < 30
	local rr170_yrange ylabel(-0.02(0.01)0.01, labsize(medlarge))
	local rr170_titlegap -60
	
	*rr180
	local rr180_x x3
	local rr180_y adult_30_40_w
	local rr180_fe fe1
	local rr180_p p1 
	local rr180_l l1 
	local rr180_xtitle Temperature (F)
	local rr180_ytitle Number of Adults 30-40
	local rr180_yrange ylabel(-0.02(0.01)0.01, labsize(medlarge))
	local rr180_titlegap -65
	
	*rr190
	local rr190_x x3
	local rr190_y adult_40_50_w
	local rr190_fe fe1
	local rr190_p p1
	local rr190_l l1 
	local rr190_xtitle Temperature (F)
	local rr190_ytitle Number of Adults 40-50
	local rr190_yrange ylabel(-0.02(0.01)0.01, labsize(medlarge))
	local rr190_titlegap -65
	
	*rr200
	local rr200_x x3
	local rr200_y adult_50_60_w
	local rr200_fe fe1
	local rr200_p p1
	local rr200_l l1 
	local rr200_xtitle Temperature (F)
	local rr200_ytitle Number of Adults 50-60
	local rr200_yrange ylabel(-0.02(0.01)0.01, labsize(medlarge))
	local rr200_titlegap -65
	
	*rr210
	local rr210_x x3
	local rr210_y adult_gte60_w
	local rr210_fe fe1
	local rr210_p p1
	local rr210_l l1 
	local rr210_xtitle Temperature (F)
	local rr210_ytitle Number of Adults > 60
	local rr210_yrange ylabel(-0.02(0.01)0.01, labsize(medlarge))
	local rr210_titlegap -60
	
	*rr220
	local rr220_x x1
	local rr220_y log_protein_pcd_w
	local rr220_fe fe1
	local rr220_p p1
	local rr220_l l1 
	local rr220_xtitle Temperature (F)
	local rr220_ytitle 100 x Log of Daily Protein Per Capita
	local rr220_yrange ylabel(-0.6(0.2)0.2, labsize(medlarge))
	local rr220_titlegap -88
	
	*rr230
	local rr230_x x1
	local rr230_y protein_home_pcd_w
	local rr230_fe fe1
	local rr230_p p1
	local rr230_l l1 
	local rr230_xtitle Temperature (F)
	local rr230_ytitle Daily Protein (kCal) Per Capita, Home-Grown
	local rr230_yrange ylabel(, labsize(medlarge))
	local rr230_titlegap -92
	
	*rr240
	local rr240_x x1
	local rr240_y protein_purchase_pcd_w
	local rr240_fe fe1
	local rr240_p p1
	local rr240_l l1 
	local rr240_xtitle Temperature (F)
	local rr240_ytitle Daily Protein (kCal) Per Capita, Purchased
	local rr240_yrange ylabel(, labsize(medlarge))
	local rr240_titlegap -87
	
	*rr250
	local rr250_x x1
	local rr250_y log_zinc_pcd_w
	local rr250_fe fe1
	local rr250_p p1
	local rr250_l l1 
	local rr250_xtitle Temperature (F)
	local rr250_ytitle 100 x Log of Daily Zinc Per Capita
	local rr250_yrange ylabel(-0.6(0.2)0.2, labsize(medlarge))
	local rr250_titlegap -80
	
	*rr260
	local rr260_x x1
	local rr260_y zinc_home_pcd_w
	local rr260_fe fe1
	local rr260_p p1
	local rr260_l l1 
	local rr260_xtitle Temperature (F)
	local rr260_ytitle Daily Zinc (mg) per Capita, Home-Grown 
	local rr260_yrange ylabel(-0.08(0.02)0.08, labsize(medlarge))
	local rr260_titlegap -90
	
	*rr270
	local rr270_x x1
	local rr270_y zinc_purchase_pcd_w
	local rr270_fe fe1
	local rr270_p p1
	local rr270_l l1 
	local rr270_xtitle Temperature (F)
	local rr270_ytitle Daily Zinc (mg) per Capita, Purchased
	local rr270_yrange ylabel(-0.08(0.02)0.08, labsize(medlarge))
	local rr270_titlegap -85
	
	*rr280
	local rr280_x x2
	local rr280_y protein_lt100p
	local rr280_fe fe1
	local rr280_p p1
	local rr280_l l1 
	local rr280_xtitle Temperature (F)
	local rr280_ytitle Households below 100% Protein (%)
	local rr280_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr280_titlegap -75
	
	*rr290
	local rr290_x x2
	local rr290_y protein_lt80p
	local rr290_fe fe1
	local rr290_p p1
	local rr290_l l1 
	local rr290_xtitle Temperature (F)
	local rr290_ytitle Households below 80% Protein (%)
	local rr290_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr290_titlegap -73
	
	*rr300
	local rr300_x x2
	local rr300_y zinc_lt80p
	local rr300_fe fe1
	local rr300_p p1
	local rr300_l l1 
	local rr300_xtitle Temperature (F)
	local rr300_ytitle Households below 80% Zinc (%)
	local rr300_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr300_titlegap -65
	
	*rr310
	local rr310_x x2
	local rr310_y zinc_lt100p
	local rr310_fe fe1
	local rr310_p p1
	local rr310_l l1 
	local rr310_xtitle Temperature (F)
	local rr310_ytitle Households below 100% Zinc (%)
	local rr310_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr310_titlegap -65
	
	*rr320
	local rr320_x x2
	local rr320_y iron_lt40p
	local rr320_fe fe1
	local rr320_p p1
	local rr320_l l1 
	local rr320_xtitle Temperature (F)
	local rr320_ytitle Households below 40% Iron (%)
	local rr320_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr320_titlegap -65
	
	
	*rr330
	local rr330_x x3
	local rr330_y adult_gte50_w
	local rr330_fe fe1
	local rr330_p p1
	local rr330_l l1 
	local rr330_xtitle Temperature (F)
	local rr330_ytitle Number of Adults > 50
	local rr330_yrange ylabel(-0.02(0.01)0.01, labsize(medlarge))
	local rr330_titlegap -60
	
	*rr340
	local rr340_x x2
	local rr340_y calories_lt50p
	local rr340_fe fe1
	local rr340_p p1
	local rr340_l l1 
	local rr340_xtitle Temperature (F)
	local rr340_ytitle Households below 50% Calories (%)
	local rr340_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr340_titlegap -70
	
	*rr350
	local rr350_x x2
	local rr350_y protein_lt50p
	local rr350_fe fe1
	local rr350_p p1
	local rr350_l l1 
	local rr350_xtitle Temperature (F)
	local rr350_ytitle Households below 50% Protein (%)
	local rr350_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr350_titlegap -70
	
	*rr360
	local rr360_x x2
	local rr360_y zinc_lt50p
	local rr360_fe fe1
	local rr360_p p1
	local rr360_l l1 
	local rr360_xtitle Temperature (F)
	local rr360_ytitle Households below 50% Zinc (%)
	local rr360_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr360_titlegap -65
	
	*rr370
	local rr370_x x2
	local rr370_y child_female_perc_w
	local rr370_fe fe1
	local rr370_p p1
	local rr370_l l1 
	local rr370_xtitle Temperature (F)
	local rr370_ytitle Percent of Female Children 
	local rr370_yrange ylabel(, labsize(medlarge))
	local rr370_titlegap -60
	
	*rr380
	local rr380_x x2
	local rr380_y adult_lt60_female_perc_w
	local rr380_fe fe1
	local rr380_p p1
	local rr380_l l1 
	local rr380_xtitle Temperature (F)
	local rr380_ytitle Percent of Female Adults < 60 
	local rr380_yrange ylabel(, labsize(medlarge))
	local rr380_titlegap -65
	
	*rr390
	local rr390_x x2
	local rr390_y adult_gte60_female_perc_w
	local rr390_fe fe1
	local rr390_p p1
	local rr390_l l1 
	local rr390_xtitle Temperature (F)
	local rr390_ytitle Percent of Female Adults >= 60 
	local rr390_yrange ylabel(, labsize(medlarge))
	local rr390_titlegap -65
	
	*rr400
	local rr400_x x2
	local rr400_y married_adult_perc_w
	local rr400_fe fe1
	local rr400_p p1
	local rr400_l l1 
	local rr400_xtitle Temperature (F)
	local rr400_ytitle Percent of Married Adults 
	local rr400_yrange ylabel(, labsize(medlarge))
	local rr400_titlegap -60
	
	*rr410
	local rr410_x x3
	local rr410_y adult_woman_lt60_w
	local rr410_fe fe1
	local rr410_p p1
	local rr410_l l1 
	local rr410_xtitle Temperature (F)
	local rr410_ytitle Adult Women < 60 
	local rr410_yrange ylabel(, labsize(medlarge))
	local rr410_titlegap -40
	
	*rr420
	local rr420_x x3
	local rr420_y adult_man_lt60_w
	local rr420_fe fe1
	local rr420_p p1
	local rr420_l l1 
	local rr420_xtitle Temperature (F)
	local rr420_ytitle Adult Men < 60 
	local rr420_yrange ylabel(, labsize(medlarge))
	local rr420_titlegap -35
	
	*rr430
	local rr430_x x3
	local rr430_y woman_lt30_w
	local rr430_fe fe1
	local rr430_p p1
	local rr430_l l1 
	local rr430_xtitle Temperature (F)
	local rr430_ytitle Adult Women < 30 
	local rr430_yrange ylabel(, labsize(medlarge))
	local rr430_titlegap -40
	
	*rr440
	local rr440_x x3
	local rr440_y man_lt30_w
	local rr440_fe fe1
	local rr440_p p1
	local rr440_l l1 
	local rr440_xtitle Temperature (F)
	local rr440_ytitle Adult Men < 30 
	local rr440_yrange ylabel(, labsize(medlarge))
	local rr440_titlegap -40
	
	*rr450
	local rr450_x x3
	local rr450_y woman_30_40_w
	local rr450_fe fe1
	local rr450_p p1
	local rr450_l l1 
	local rr450_xtitle Temperature (F)
	local rr450_ytitle Adult Women 30-40
	local rr450_yrange ylabel(, labsize(medlarge))
	local rr450_titlegap -45
	
	*rr460
	local rr460_x x3
	local rr460_y man_30_40_w
	local rr460_fe fe1
	local rr460_p p1
	local rr460_l l1 
	local rr460_xtitle Temperature (F)
	local rr460_ytitle Adult Men 30-40
	local rr460_yrange ylabel(, labsize(medlarge))
	local rr460_titlegap -40
	
	*rr470
	local rr470_x x3
	local rr470_y woman_40_50_w
	local rr470_fe fe1
	local rr470_p p1
	local rr470_l l1 
	local rr470_xtitle Temperature (F)
	local rr470_ytitle Adult Women 40-50
	local rr470_yrange ylabel(, labsize(medlarge))
	local rr470_titlegap -45
	
	*rr480
	local rr480_x x3
	local rr480_y man_40_50_w
	local rr480_fe fe1
	local rr480_p p1
	local rr480_l l1 
	local rr480_xtitle Temperature (F)
	local rr480_ytitle Adult Men 40-50
	local rr480_yrange ylabel(, labsize(medlarge))
	local rr480_titlegap -40
	
	*rr490
	local rr490_x x3
	local rr490_y woman_50_60_w
	local rr490_fe fe1
	local rr490_p p1
	local rr490_l l1 
	local rr490_xtitle Temperature (F)
	local rr490_ytitle Adult Women 50-60
	local rr490_yrange ylabel(, labsize(medlarge))
	local rr490_titlegap -45
	
	*rr500
	local rr500_x x3
	local rr500_y man_50_60_w
	local rr500_fe fe1
	local rr500_p p1
	local rr500_l l1 
	local rr500_xtitle Temperature (F)
	local rr500_ytitle Adult Men 50-60
	local rr500_yrange ylabel(, labsize(medlarge))
	local rr500_titlegap -40
	
	*rr510
	local rr510_x x2
	local rr510_y adult_lt30_female_perc_w
	local rr510_fe fe1
	local rr510_p p1
	local rr510_l l1 
	local rr510_xtitle Temperature (F)
	local rr510_ytitle Percent of Female Adults < 30 
	local rr510_yrange ylabel(, labsize(medlarge))
	local rr510_titlegap -65
	
	*rr520
	local rr520_x x2
	local rr520_y adult_30_40_female_perc_w
	local rr520_fe fe1
	local rr520_p p1
	local rr520_l l1 
	local rr520_xtitle Temperature (F)
	local rr520_ytitle Percent of Female Adults 30-40 
	local rr520_yrange ylabel(, labsize(medlarge))
	local rr520_titlegap -65
	
	*rr530
	local rr530_x x2
	local rr530_y adult_40_50_female_perc_w
	local rr530_fe fe1
	local rr530_p p1
	local rr530_l l1 
	local rr530_xtitle Temperature (F)
	local rr530_ytitle Percent of Female Adults 40-50 
	local rr530_yrange ylabel(, labsize(medlarge))
	local rr530_titlegap -65
	
	*rr540
	local rr540_x x2
	local rr540_y adult_50_60_female_perc_w
	local rr540_fe fe1
	local rr540_p p1
	local rr540_l l1 
	local rr540_xtitle Temperature (F)
	local rr540_ytitle Percent of Female Adults 50-60 
	local rr540_yrange ylabel(, labsize(medlarge))
	local rr540_titlegap -65
	
	*rr550
	local rr550_x x3
	local rr550_y man_gte60_w
	local rr550_fe fe1
	local rr550_p p1
	local rr550_l l1 
	local rr550_xtitle Temperature (F)
	local rr550_ytitle Men >= 60
	local rr550_yrange ylabel(, labsize(medlarge))
	local rr550_titlegap -40
	
	*rr560
	local rr560_x x3
	local rr560_y woman_gte60_w
	local rr560_fe fe1
	local rr560_p p1
	local rr560_l l1 
	local rr560_xtitle Temperature (F)
	local rr560_ytitle Women >= 60
	local rr560_yrange ylabel(, labsize(medlarge))
	local rr560_titlegap -45
	
	*rr570
	local rr570_x x3
	local rr570_y male_lt18_w
	local rr570_fe fe1
	local rr570_p p1
	local rr570_l l1 
	local rr570_xtitle Temperature (F)
	local rr570_ytitle Boys < 18
	local rr570_yrange ylabel(, labsize(medlarge))
	local rr570_titlegap -40
	
	*rr580
	local rr580_x x3
	local rr580_y female_lt18_w
	local rr580_fe fe1
	local rr580_p p1
	local rr580_l l1 
	local rr580_xtitle Temperature (F)
	local rr580_ytitle Girls < 18
	local rr580_yrange ylabel(, labsize(medlarge))
	local rr580_titlegap -40
	
	*rr590
	local rr590_x x3
	local rr590_y married_woman_lt30_w
	local rr590_fe fe1
	local rr590_p p1
	local rr590_l l1 
	local rr590_xtitle Temperature (F)
	local rr590_ytitle Married Women < 30
	local rr590_yrange ylabel(, labsize(medlarge))
	local rr590_titlegap -50
	
	*rr600
	local rr600_x x3
	local rr600_y unmarried_woman_lt30_w
	local rr600_fe fe1
	local rr600_p p1
	local rr600_l l1 
	local rr600_xtitle Temperature (F)
	local rr600_ytitle Unmarried Women < 30
	local rr600_yrange ylabel(, labsize(medlarge))
	local rr600_titlegap -50
	
	*rr610
	local rr610_x x3
	local rr610_y married_man_lt30_w
	local rr610_fe fe1
	local rr610_p p1
	local rr610_l l1 
	local rr610_xtitle Temperature (F)
	local rr610_ytitle Married Men < 30
	local rr610_yrange ylabel(, labsize(medlarge))
	local rr610_titlegap -40
	
	*rr620
	local rr620_x x3
	local rr620_y unmarried_man_lt30_w
	local rr620_fe fe1
	local rr620_p p1
	local rr620_l l1 
	local rr620_xtitle Temperature (F)
	local rr620_ytitle Unmarried Men < 30
	local rr620_yrange ylabel(, labsize(medlarge))
	local rr620_titlegap -40
	
	*rr630
	local rr630_x x3
	local rr630_y infant_w
	local rr630_fe fe1
	local rr630_p p1
	local rr630_l l1 
	local rr630_xtitle Temperature (F)
	local rr630_ytitle Infants
	local rr630_yrange ylabel(, labsize(medlarge))
	local rr630_titlegap -30
	
	*rr640
	local rr640_x x1
	local rr640_y log_thiamine_pcd_w
	local rr640_fe fe1
	local rr640_p p1
	local rr640_l l1 
	local rr640_xtitle Temperature (F)
	local rr640_ytitle 100 x Log of Daily Thiamine Per Capita
	local rr640_yrange ylabel(-0.6(0.2)0.2, labsize(medlarge))
	local rr640_titlegap -90
	
	*rr650
	local rr650_x x1
	local rr650_y thiamine_home_pcd_w
	local rr650_fe fe1
	local rr650_p p1
	local rr650_l l1 
	local rr650_xtitle Temperature (F)
	local rr650_ytitle Daily Thiamine (kCal) Per Capita, Home-Grown
	local rr650_yrange ylabel(, labsize(medlarge))
	local rr650_titlegap -95
	
	*rr660
	local rr660_x x1
	local rr660_y thiamine_purchase_pcd_w
	local rr660_fe fe1
	local rr660_p p1
	local rr660_l l1 
	local rr660_xtitle Temperature (F)
	local rr660_ytitle Daily Thiamine (kCal) Per Capita, Purchased
	local rr660_yrange ylabel(, labsize(medlarge))
	local rr660_titlegap -90
	
	*rr670
	local rr670_x x2
	local rr670_y thiamine_lt100p
	local rr670_fe fe1
	local rr670_p p1
	local rr670_l l1 
	local rr670_xtitle Temperature (F)
	local rr670_ytitle Households below 100% Thiamine (%)
	local rr670_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr670_titlegap -75
	
	*rr680
	local rr680_x x2
	local rr680_y thiamine_lt80p
	local rr680_fe fe1
	local rr680_p p1
	local rr680_l l1 
	local rr680_xtitle Temperature (F)
	local rr680_ytitle Households below 80% Thiamine (%)
	local rr680_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr680_titlegap -75

	*rr690
	local rr690_x x2
	local rr690_y thiamine_lt50p
	local rr690_fe fe1
	local rr690_p p1
	local rr690_l l1 
	local rr690_xtitle Temperature (F)
	local rr690_ytitle Households below 50% Thiamine (%)
	local rr690_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr690_titlegap -75

	*rr700
	local rr700_x x1
	local rr700_y log_riboflavin_pcd_w
	local rr700_fe fe1
	local rr700_p p1
	local rr700_l l1 
	local rr700_xtitle Temperature (F)
	local rr700_ytitle 100 x Log of Daily Riboflavin Per Capita
	local rr700_yrange ylabel(-0.6(0.2)0.2, labsize(medlarge))
	local rr700_titlegap -90

	*rr710
	local rr710_x x1
	local rr710_y riboflavin_home_pcd_w
	local rr710_fe fe1
	local rr710_p p1
	local rr710_l l1 
	local rr710_xtitle Temperature (F)
	local rr710_ytitle Daily Riboflavin (kCal) Per Capita, Home-Grown
	local rr710_yrange ylabel(, labsize(medlarge))
	local rr710_titlegap -100

	*rr720
	local rr720_x x1
	local rr720_y riboflavin_purchase_pcd_w
	local rr720_fe fe1
	local rr720_p p1
	local rr720_l l1 
	local rr720_xtitle Temperature (F)
	local rr720_ytitle Daily Riboflavin (kCal) Per Capita, Purchased
	local rr720_yrange ylabel(, labsize(medlarge))
	local rr720_titlegap -95

	*rr730
	local rr730_x x2
	local rr730_y riboflavin_lt100p
	local rr730_fe fe1
	local rr730_p p1
	local rr730_l l1 
	local rr730_xtitle Temperature (F)
	local rr730_ytitle Households below 100% Riboflavin (%)
	local rr730_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr730_titlegap -80

	*rr740
	local rr740_x x2
	local rr740_y riboflavin_lt80p
	local rr740_fe fe1
	local rr740_p p1
	local rr740_l l1 
	local rr740_xtitle Temperature (F)
	local rr740_ytitle Households below 80% Riboflavin (%)
	local rr740_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr740_titlegap -80

	*rr750
	local rr750_x x2
	local rr750_y riboflavin_lt50p
	local rr750_fe fe1
	local rr750_p p1
	local rr750_l l1 
	local rr750_xtitle Temperature (F)
	local rr750_ytitle Households below 50% Riboflavin (%)
	local rr750_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr750_titlegap -80

	*rr760
	local rr760_x x1
	local rr760_y log_niacin_pcd_w
	local rr760_fe fe1
	local rr760_p p1
	local rr760_l l1 
	local rr760_xtitle Temperature (F)
	local rr760_ytitle 100 x Log of Daily Niacin Per Capita
	local rr760_yrange ylabel(-0.6(0.2)0.2, labsize(medlarge))
	local rr760_titlegap -85
	
	*rr770
	local rr770_x x1
	local rr770_y niacin_home_pcd_w
	local rr770_fe fe1
	local rr770_p p1
	local rr770_l l1 
	local rr770_xtitle Temperature (F)
	local rr770_ytitle Daily Niacin (kCal) Per Capita, Home-Grown
	local rr770_yrange ylabel(, labsize(medlarge))
	local rr770_titlegap -95

	*rr780
	local rr780_x x1
	local rr780_y niacin_purchase_pcd_w
	local rr780_fe fe1
	local rr780_p p1
	local rr780_l l1 
	local rr780_xtitle Temperature (F)
	local rr780_ytitle Daily Niacin (kCal) Per Capita, Purchased
	local rr780_yrange ylabel(, labsize(medlarge))
	local rr780_titlegap -90

	*rr790
	local rr790_x x2
	local rr790_y niacin_lt100p
	local rr790_fe fe1
	local rr790_p p1
	local rr790_l l1 
	local rr790_xtitle Temperature (F)
	local rr790_ytitle Households below 100% Niacin (%)
	local rr790_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr790_titlegap -75

	*rr800
	local rr800_x x2
	local rr800_y niacin_lt80p
	local rr800_fe fe1
	local rr800_p p1
	local rr800_l l1 
	local rr800_xtitle Temperature (F)
	local rr800_ytitle Households below 80% Niacin (%)
	local rr800_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr800_titlegap -70

	*rr810
	local rr810_x x2
	local rr810_y niacin_lt50p
	local rr810_fe fe1
	local rr810_p p1
	local rr810_l l1 
	local rr810_xtitle Temperature (F)
	local rr810_ytitle Households below 50% Niacin (%)
	local rr810_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr810_titlegap -70

	*rr820
	local rr820_x x1
	local rr820_y log_ascorbic_acid_pcd_w
	local rr820_fe fe1
	local rr820_p p1
	local rr820_l l1 
	local rr820_xtitle Temperature (F)
	local rr820_ytitle 100 x Log of Daily Ascorbic Acid Per Capita
	local rr820_yrange ylabel(-0.6(0.2)0.2, labsize(medlarge))
	local rr820_titlegap -95

	*rr830
	local rr830_x x1
	local rr830_y ascorbic_acid_home_pcd_w
	local rr830_fe fe1
	local rr830_p p1
	local rr830_l l1 
	local rr830_xtitle Temperature (F)
	local rr830_ytitle Daily Ascorbic Acid (kCal) Per Capita, Home-Grown
	local rr830_yrange ylabel(, labsize(medlarge))
	local rr830_titlegap -105

	*rr840
	local rr840_x x1
	local rr840_y ascorbic_acid_purchase_pcd_w
	local rr840_fe fe1
	local rr840_p p1
	local rr840_l l1 
	local rr840_xtitle Temperature (F)
	local rr840_ytitle Daily Ascorbic Acid (kCal) Per Capita, Purchased
	local rr840_yrange ylabel(, labsize(medlarge))
	local rr840_titlegap -105

	*rr850
	local rr850_x x2
	local rr850_y ascorbic_acid_lt100p
	local rr850_fe fe1
	local rr850_p p1
	local rr850_l l1 
	local rr850_xtitle Temperature (F)
	local rr850_ytitle Households below 100% Ascorbic Acid (%)
	local rr850_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr850_titlegap -85

	*rr860
	local rr860_x x2
	local rr860_y ascorbic_acid_lt80p
	local rr860_fe fe1
	local rr860_p p1
	local rr860_l l1 
	local rr860_xtitle Temperature (F)
	local rr860_ytitle Households below 80% Ascorbic Acid (%)
	local rr860_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr860_titlegap -85

	*rr870
	local rr870_x x2
	local rr870_y ascorbic_acid_lt50p
	local rr870_fe fe1
	local rr870_p p1
	local rr870_l l1 
	local rr870_xtitle Temperature (F)
	local rr870_ytitle Households below 50% Ascorbic Acid (%)
	local rr870_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr870_titlegap -85
	
	*rr880
	local rr880_x x2
	local rr880_y zinc_lt60p
	local rr880_fe fe1
	local rr880_p p1
	local rr880_l l1 
	local rr880_xtitle Temperature (F)
	local rr880_ytitle Households below 60% Zinc (%)
	local rr880_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr880_titlegap -65
	
	
	*rr890
	local rr890_x x2
	local rr890_y protein_lt60p
	local rr890_fe fe1
	local rr890_p p1
	local rr890_l l1 
	local rr890_xtitle Temperature (F)
	local rr890_ytitle Households below 60% Protein (%)
	local rr890_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr890_titlegap -73
	
	*rr900
	local rr900_x x2
	local rr900_y thiamine_lt60p
	local rr900_fe fe1
	local rr900_p p1
	local rr900_l l1 
	local rr900_xtitle Temperature (F)
	local rr900_ytitle Households below 60% Thiamine (%)
	local rr900_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr900_titlegap -75
	
	*rr910
	local rr910_x x2
	local rr910_y riboflavin_lt60p
	local rr910_fe fe1
	local rr910_p p1
	local rr910_l l1 
	local rr910_xtitle Temperature (F)
	local rr910_ytitle Households below 60% Riboflavin (%)
	local rr910_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr910_titlegap -80
	
	*rr920
	local rr920_x x2
	local rr920_y niacin_lt60p
	local rr920_fe fe1
	local rr920_p p1
	local rr920_l l1 
	local rr920_xtitle Temperature (F)
	local rr920_ytitle Households below 60% Niacin (%)
	local rr920_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr920_titlegap -70
	
	*rr930
	local rr930_x x2
	local rr930_y ascorbic_acid_lt60p
	local rr930_fe fe1
	local rr930_p p1
	local rr930_l l1 
	local rr930_xtitle Temperature (F)
	local rr930_ytitle Households below 60% Ascorbic Acid (%)
	local rr930_yrange ylabel(-0.2(0.2)0.8, labsize(medlarge))
	local rr930_titlegap -85

	
	local plot_ops ylabel(,  angle(0) nogrid labcolor(gs4) tlcolor(gs4)) yline(0, lcolor(gs12)) graphregion(fcolor(white) lcolor(white) margin(large)) plotregion(lstyle(white)) lp(solid) lw(medthick)  xlabel(, labcolor(gs4) tlcolor(gs4) labsize(medlarge)) mcolor(gs1) vertical ciopts(recast(rcap) lcolor(gs1))
	
	
	foreach grow_index in grow{
	*define labels
	*l1
	local l1  zeroslast_y`grow_index' = "<70"  tmax_70_80last_y`grow_index' = "70-80" tmax_80_90last_y`grow_index' = "80-90" tmax_90_100last_y`grow_index' = "90-100" tmax_100_110last_y`grow_index' = "100-110"  tmax_gt110last_y`grow_index' = "{&ge}110"
		
		foreach run in `plotlist'{
			set scheme s2mono
				
				cd `output' 
				estimates use regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster
				insheet using regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster.txt, clear
				gen num_obs = e(N)
				format num_obs %9.0fc
				tostring num_obs, replace force usedisplayformat
				cd `table_coef_path'
				export delim num_obs using "`run'_``run'_y'_numobs.txt"  if _n == 1, novarnames replace delimiter(" ")
				drop num_obs
				cd `graph_path'
				foreach time_name in last_y`grow_index'{
					coefplot, keep(*: *`time_name') drop(rain_shock* ) omitted ``run'_order' ``run'_yrange' xtitle(``run'_xtitle', color(gs1) size(medlarge)) ytitle("``run'_ytitle'", placement(n) orientation(horizontal) color(gs1) size(medlarge)) `plot_ops' coeflabels(```run'_l'') ysc(titlegap(``run'_titlegap') outergap(0) lcolor(gs1)) 
					gr_edit yaxis1.title.DragBy 5 0
					graph export coefplot_regols_`run'_``run'_y'_``run'_x'_``run'_fe'_2003_2012_distcluster_`time_name'.pdf, replace
			} 	
		}
	}
	
	/*
	foreach run in `plotlist'{
		cd `output'
		estimates use regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster
		insheet using /Users/paulstainier/Dropbox/1_rii/4_analysis/output/tmax_spline_dummydata_lastygrow_70.csv, clear
		keep if tmax_raw >= 50 & tmax_raw <= 115
		predict p
		predict p1, stdp
		gen p_m1 = p - 1.96*p1
		gen p_p1 = p + 1.96*p1
		twoway connected p tmax_raw || connected p_m1 tmax_raw  || connected p_p1 tmax_raw
		cd `graph_path'
		graph export coefplot_splineregols_`run'_``run'_y'_``run'_x'_``run'_fe'_2003_2012_distcluster_`time_name'.pdf, replace
	}
	*/
}



***************************
*
*plot_home_purch
*
*plot regressions 
*for each nutrient home-grown vs. 
*purchased
*
***************************
if "`plot_home_purch'" == "yes"{
	
	*rr20
	local rr20_x x1
	local rr20_y calories_home_pcd_w
	local rr20_fe fe1
	local rr20_p p1
	local rr20_l l1 
	local rr20_xtitle Temperature (F)
	local rr20_ytitle Daily Calories (kCal) Per Capita
	local rr20_yrange ylabel(-10(2)10, labsize(medlarge))
	local rr20_titlegap -65
	
	*rr30
	local rr30_x x1
	local rr30_y calories_purchase_pcd_w
	local rr30_fe fe1
	local rr30_p p1
	local rr30_l l1 
	local rr30_xtitle Temperature (F)
	local rr30_ytitle Daily Calories (kCal) Per Capita
	local rr30_yrange ylabel(-10(2)10, labsize(medlarge))
	local rr30_titlegap -65
	

	*rr60
	local rr60_x x1
	local rr60_y iron_home_pcd_w
	local rr60_fe fe1
	local rr60_p p1
	local rr60_l l1 
	local rr60_xtitle Temperature (F)
	local rr60_ytitle Daily Iron (mg) per Capita
	local rr60_yrange ylabel(-0.08(0.02)0.08, labsize(medlarge))
	local rr60_titlegap -63
	
	*rr70
	local rr70_x x1
	local rr70_y iron_purchase_pcd_w
	local rr70_fe fe1
	local rr70_p p1
	local rr70_l l1 
	local rr70_xtitle Temperature (F)
	local rr70_ytitle Daily Iron (mg) per Capita
	local rr70_yrange ylabel(-0.08(0.02)0.08, labsize(medlarge))
	local rr70_titlegap -63

	
	*rr230
	local rr230_x x1
	local rr230_y protein_home_pcd_w
	local rr230_fe fe1
	local rr230_p p1
	local rr230_l l1 
	local rr230_xtitle Temperature (F)
	local rr230_ytitle Daily Protein (g) Per Capita
	local rr230_yrange ylabel(-0.3(0.1)0.3, labsize(medlarge))
	local rr230_titlegap -70
	
	*rr240
	local rr240_x x1
	local rr240_y protein_purchase_pcd_w
	local rr240_fe fe1
	local rr240_p p1
	local rr240_l l1 
	local rr240_xtitle Temperature (F)
	local rr240_ytitle Daily Protein (kCal) Per Capita
	local rr240_yrange ylabel(-0.3(0.1)0.3, labsize(medlarge))
	local rr240_titlegap -70
	

	*rr260
	local rr260_x x1
	local rr260_y zinc_home_pcd_w
	local rr260_fe fe1
	local rr260_p p1
	local rr260_l l1 
	local rr260_xtitle Temperature (F)
	local rr260_ytitle Daily Zinc (mg) per Capita
	local rr260_yrange ylabel(-0.06(0.02)0.06, labsize(medlarge))
	local rr260_titlegap -63
	
	*rr270
	local rr270_x x1
	local rr270_y zinc_purchase_pcd_w
	local rr270_fe fe1
	local rr270_p p1
	local rr270_l l1 
	local rr270_xtitle Temperature (F)
	local rr270_ytitle Daily Zinc (mg) per Capita
	local rr270_yrange ylabel(-0.06(0.02)0.06, labsize(medlarge))
	local rr270_titlegap -63
	
	
	*rr650
	local rr650_x x1
	local rr650_y thiamine_home_pcd_w
	local rr650_fe fe1
	local rr650_p p1
	local rr650_l l1 
	local rr650_xtitle Temperature (F)
	local rr650_ytitle Daily Thiamine (mg) Per Capita
	local rr650_yrange ylabel(-0.006(0.002)0.006, labsize(medlarge))
	local rr650_titlegap -68
	
	*rr660
	local rr660_x x1
	local rr660_y thiamine_purchase_pcd_w
	local rr660_fe fe1
	local rr660_p p1
	local rr660_l l1 
	local rr660_xtitle Temperature (F)
	local rr660_ytitle Daily Thiamine (mg) Per Capita
	local rr660_yrange ylabel(-0.006(0.002)0.006, labsize(medlarge))
	local rr660_titlegap -68
	


	*rr710
	local rr710_x x1
	local rr710_y riboflavin_home_pcd_w
	local rr710_fe fe1
	local rr710_p p1
	local rr710_l l1 
	local rr710_xtitle Temperature (F)
	local rr710_ytitle Daily Riboflavin (mg) Per Capita
	local rr710_yrange ylabel(-0.006(0.002)0.006, labsize(medlarge))
	local rr710_titlegap -70

	*rr720
	local rr720_x x1
	local rr720_y riboflavin_purchase_pcd_w
	local rr720_fe fe1
	local rr720_p p1
	local rr720_l l1 
	local rr720_xtitle Temperature (F)
	local rr720_ytitle Daily Riboflavin (mg) Per Capita
	local rr720_yrange ylabel(-0.006(0.002)0.006, labsize(medlarge))
	local rr720_titlegap -70

	
	*rr770
	local rr770_x x1
	local rr770_y niacin_home_pcd_w
	local rr770_fe fe1
	local rr770_p p1
	local rr770_l l1 
	local rr770_xtitle Temperature (F)
	local rr770_ytitle Daily Niacin (mg) Per Capita
	local rr770_yrange ylabel(-0.08(0.02)0.08, labsize(medlarge))
	local rr770_titlegap -68

	*rr780
	local rr780_x x1
	local rr780_y niacin_purchase_pcd_w
	local rr780_fe fe1
	local rr780_p p1
	local rr780_l l1 
	local rr780_xtitle Temperature (F)
	local rr780_ytitle Daily Niacin (mg) Per Capita
	local rr780_yrange ylabel(-0.08(0.02)0.08, labsize(medlarge))
	local rr780_titlegap -68


	*rr830
	local rr830_x x1
	local rr830_y ascorbic_acid_home_pcd_w
	local rr830_fe fe1
	local rr830_p p1
	local rr830_l l1 
	local rr830_xtitle Temperature (F)
	local rr830_ytitle Daily Ascorbic Acid (mg) Per Capita
	local rr830_yrange ylabel(-0.4(0.1)0.4, labsize(medlarge))
	local rr830_titlegap -85

	*rr840
	local rr840_x x1
	local rr840_y ascorbic_acid_purchase_pcd_w
	local rr840_fe fe1
	local rr840_p p1
	local rr840_l l1 
	local rr840_xtitle Temperature (F)
	local rr840_ytitle Daily Ascorbic Acid (mg) Per Capita
	local rr840_yrange ylabel(-0.4(0.1)0.4, labsize(medlarge))
	local rr840_titlegap -85


	
	local plot_ops ylabel(,  angle(0) nogrid labcolor(gs4) tlcolor(gs4)) yline(0, lcolor(gs12)) graphregion(fcolor(white) lcolor(white) margin(large)) plotregion(lstyle(white)) lp(solid) lw(medthick)  xlabel(, labcolor(gs4) tlcolor(gs4) labsize(medlarge))vertical 
	
	
	local home_list "rr20 rr60 rr230 rr260 rr650 rr710 rr770 rr830"
	local purchase_list "rr30 rr70 rr240 rr270 rr660 rr720 rr780 rr840"
	local n : word count `home_list'
	
	forvalues i = 1/`n' {
		local run1 : word `i' of `home_list'
		local run2 : word `i' of `purchase_list'
		local grow_index = "grow"
		*define labels
		*l1
		local l1  zeroslast_y`grow_index' = "<70"  tmax_70_80last_y`grow_index' = "70-80" tmax_80_90last_y`grow_index' = "80-90" tmax_90_100last_y`grow_index' = "90-100" tmax_100_110last_y`grow_index' = "100-110"  tmax_gt110last_y`grow_index' = "{&ge}110"
		set scheme s2mono
			
			cd `output' 
			estimates use regols_`run1'_``run1'_y'_``run1'_x'_``run1'_p'_``run1'_fe'_2003_2012_distcluster
			est store model1
			estimates use regols_`run2'_``run2'_y'_``run2'_x'_``run2'_p'_``run2'_fe'_2003_2012_distcluster
			est store model2

			cd `graph_path'
			foreach time_name in last_y`grow_index'{
				coefplot (model1, offset(-0.1) color(blue) ciopts(recast(rcap) lcolor(blue))) (model2, offset(0.1) color(orange) ciopts(recast(rcap) lcolor(orange))), keep(*: *`time_name') drop(rain_shock* ) omitted ``run1'_yrange' xtitle(``run1'_xtitle', color(gs1) size(medlarge)) ytitle("``run1'_ytitle'", placement(n) orientation(horizontal) color(gs1) size(medlarge)) `plot_ops' coeflabels(```run1'_l'') ysc(titlegap(``run1'_titlegap') outergap(0) lcolor(gs1)) legend(order(2 "Home Grown" "" 4 "Purchased") position(12) ring(0) cols(1) region(lwidth(none))) 
				gr_edit yaxis1.title.DragBy 5 0
				graph export coefplot_regols_`run1'home_`run2'purchase_``run1'_y'_2003_2012_distcluster_`time_name'.pdf, replace
		} 	
	}
}



***************************
*
*plot_reghdfe_s10
*
*plot regressions for
*schedule 10
*
***************************
if "`plot_reghdfe_s10'" == "yes"{

	local plotlist
	foreach num of numlist 10(10)170 {
		local plotlist `plotlist' r10_`num'
	}	
	
	*r10_10
	local r10_10_x x8
	local r10_10_y working_principal
	local r10_10_fe fe1
	local r10_10_p p1
	local r10_10_cond work_age
	local r10_10_l l1 
	local r10_10_xtitle Temperature (F)
	local r10_10_ytitle Percent Working
	local r10_10_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_10_titlegap -48
	
	*r10_20
	local r10_20_x x8
	local r10_20_y manuf_principal
	local r10_20_fe fe1
	local r10_20_p p1
	local r10_20_cond work_age
	local r10_20_l l1 
	local r10_20_xtitle Temperature (F)
	local r10_20_ytitle Percent Working in Manufacturing
	local r10_20_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_20_titlegap -70
	
	*r10_30
	local r10_30_x x8
	local r10_30_y const_principal
	local r10_30_fe fe1
	local r10_30_p p1
	local r10_30_cond work_age
	local r10_30_l l1 
	local r10_30_xtitle Temperature (F)
	local r10_30_ytitle Percent Working in Construction
	local r10_30_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_30_titlegap -70
	
	*r10_40
	local r10_40_x x8
	local r10_40_y ag_principal
	local r10_40_fe fe1
	local r10_40_p p1
	local r10_40_cond work_age
	local r10_40_l l1 
	local r10_40_xtitle Temperature (F)
	local r10_40_ytitle Percent Working in Agriculture
	local r10_40_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_40_titlegap -73
	
	*r10_50
	local r10_50_x x8
	local r10_50_y unempl_principal
	local r10_50_fe fe1
	local r10_50_p p1
	local r10_50_cond work_age
	local r10_50_l l1 
	local r10_50_xtitle Temperature (F)
	local r10_50_ytitle Percent Unemployed
	local r10_50_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_50_titlegap -50
	
	*r10_60
	local r10_60_x x8
	local r10_60_y domestic_duties_principal
	local r10_60_fe fe1
	local r10_60_p p1
	local r10_60_cond work_age
	local r10_60_l l1 
	local r10_60_xtitle Temperature (F)
	local r10_60_ytitle Percent Working in Domestic Duties
	local r10_60_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_60_titlegap -75
	
	*r10_70
	local r10_70_x x8
	local r10_70_y in_school_principal
	local r10_70_fe fe2
	local r10_70_p p1
	local r10_70_cond school_age
	local r10_70_l l1 
	local r10_70_xtitle Temperature (F)
	local r10_70_ytitle Percent in School
	local r10_70_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_70_titlegap -45
	
	*r10_80
	local r10_80_x x8
	local r10_80_y working_principal
	local r10_80_fe fe2
	local r10_80_p p1
	local r10_80_cond school_age
	local r10_80_l l1 
	local r10_80_xtitle Temperature (F)
	local r10_80_ytitle Percent of School-Age Working
	local r10_80_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_80_titlegap -70
	
	*r10_90
	local r10_90_x x8
	local r10_90_y nonag_occ_principal
	local r10_90_fe fe1
	local r10_90_p p1
	local r10_90_cond work_age
	local r10_90_l l1 
	local r10_90_xtitle Temperature (F)
	local r10_90_ytitle Percent Working in Non-Ag Occ
	local r10_90_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_90_titlegap -73
	
	*r10_100
	local r10_100_x x8
	local r10_100_y ag_principal
	local r10_100_fe fe2
	local r10_100_p p1
	local r10_100_cond school_age
	local r10_100_l l1 
	local r10_100_xtitle Temperature (F)
	local r10_100_ytitle Percent of School-Age Working in Ag
	local r10_100_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_100_titlegap -90
	
	*r10_110
	local r10_110_x x8
	local r10_110_y nonag_occ_principal
	local r10_110_fe fe1
	local r10_110_p p1
	local r10_110_cond school_age
	local r10_110_l l1 
	local r10_110_xtitle Temperature (F)
	local r10_110_ytitle Percent of School-Age Working in Non-Ag
	local r10_110_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_110_titlegap -95
	
	*r10_120
	local r10_120_x x8
	local r10_120_y ag_at_home_principal
	local r10_120_fe fe1
	local r10_120_p p1
	local r10_120_cond work_age
	local r10_120_l l1 
	local r10_120_xtitle Temperature (F)
	local r10_120_ytitle Percent Working in Agriculture at Home
	local r10_120_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_120_titlegap -93
	
	*r10_130
	local r10_130_x x8
	local r10_130_y ag_away_principal
	local r10_130_fe fe1
	local r10_130_p p1
	local r10_130_cond work_age
	local r10_130_l l1 
	local r10_130_xtitle Temperature (F)
	local r10_130_ytitle Percent Working in Agriculture away from Home
	local r10_130_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_130_titlegap -108
	
	*r10_140
	local r10_140_x x8
	local r10_140_y nonag_at_home_principal
	local r10_140_fe fe1
	local r10_140_p p1
	local r10_140_cond work_age
	local r10_140_l l1 
	local r10_140_xtitle Temperature (F)
	local r10_140_ytitle Percent Working in Non-Ag Occ at Home
	local r10_140_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_140_titlegap -95
	
	*r10_150
	local r10_150_x x8
	local r10_150_y nonag_away_principal
	local r10_150_fe fe1
	local r10_150_p p1
	local r10_150_cond work_age
	local r10_150_l l1 
	local r10_150_xtitle Temperature (F)
	local r10_150_ytitle Percent Working in Non-Ag Occ away from Home
	local r10_150_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_150_titlegap -110
	
	*r10_160
	local r10_160_x x8
	local r10_160_y working_at_home_principal
	local r10_160_fe fe1
	local r10_160_p p1
	local r10_160_cond work_age
	local r10_160_l l1 
	local r10_160_xtitle Temperature (F)
	local r10_160_ytitle Percent Working at Home
	local r10_160_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_160_titlegap -50
	
	*r10_170
	local r10_170_x x8
	local r10_170_y working_away_principal
	local r10_170_fe fe1
	local r10_170_p p1
	local r10_170_cond work_age
	local r10_170_l l1 
	local r10_170_xtitle Temperature (F)
	local r10_170_ytitle Percent Working away from Home
	local r10_170_yrange ylabel(-0.6(0.2)0.6, labsize(medlarge))
	local r10_170_titlegap -60

	
	local plot_ops ylabel(,  angle(0) nogrid labcolor(gs4) tlcolor(gs4)) yline(0, lcolor(gs12)) graphregion(fcolor(white) lcolor(white) margin(large)) plotregion(lstyle(white)) lp(solid) lw(medthick)  xlabel(, labcolor(gs4) tlcolor(gs4) labsize(medlarge)) mcolor(gs1) vertical ciopts(recast(rcap) lcolor(gs1))
	
	
	foreach grow_index in grow{
		foreach time_name in last_y`grow_index' this_y`grow_index'{
			*define labels
			*l1
			local l1 zeros`time_name' = "<70" tmax_70_80`time_name' = "70-80" tmax_80_90`time_name' = "80-90" tmax_90_100`time_name' = "90-100"  tmax_100_110`time_name' = "100-110" tmax_gt110`time_name' =  "{&ge}110"

			
			foreach run in `plotlist'{
				set scheme s2mono
				
				cd `output' 
				estimates use regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_distcluster_``run'_cond'
				insheet using regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_distcluster_``run'_cond'.txt, clear
				gen num_obs = e(N)
				format num_obs %9.0fc
				tostring num_obs, replace force usedisplayformat
				cd `table_coef_path'
				export delim num_obs using "`run'_``run'_y'_numobs.txt"  if _n == 1, novarnames replace delimiter(" ")
				drop num_obs
				cd `graph_path'
				coefplot, keep(*: *`time_name') drop(rain_shock* ) omitted ``run'_order' ``run'_yrange' xtitle(``run'_xtitle', color(gs1) size(medlarge)) ytitle("``run'_ytitle'", placement(n) orientation(horizontal) color(gs1) size(medlarge)) `plot_ops' coeflabels(```run'_l'') ysc(titlegap(``run'_titlegap') outergap(0) lcolor(gs1)) 
				gr_edit yaxis1.title.DragBy 5 0
				graph export coefplot_regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2004_2012_distcluster_``run'_cond'_`time_name'.pdf, replace
			} 	
		}
	}
}




***************************
*
*plot_reghdfe_nfhs_by_age
*
*plot regressions for nfhs
*mortality rate by age
*
***************************
if "`plot_reghdfe_nfhs_by_age'" == "yes"{

	local plotlist
	foreach num of numlist 10 20 30 40 11 21 31 41{
			local plotlist `plotlist' r`num'
	}
	
	*define regressions
	*r10
	local r10_x x1
	local r10_y log_death_rate_lt18_p1000_w
	local r10_fe fe2
	local r10_p p1
	local r10_l l1 
	local r10_xtitle Temperature (F)
	local r10_ytitle Log Death Rate Below 18 
	local r10_yrange ylabel(-0.02(0.005)0.02, labsize(medlarge))
	local r10_ytitlegap -65
	
	*r11
	local r11_x x2
	local r11_y log_death_rate_lt18_p1000_w
	local r11_fe fe2
	local r11_p p2
	local r11_l l1 
	local r11_xtitle Temperature (F)
	local r11_ytitle Log Death Rate Below 18 
	local r11_yrange ylabel(-0.02(0.005)0.02, labsize(medlarge))
	local r11_ytitlegap -65
	
	*r20
	local r20_x x1
	local r20_y log_death_rate_18_39_p1000_w
	local r20_fe fe2
	local r20_p p1
	local r20_l l1 
	local r20_xtitle Temperature (F)
	local r20_ytitle Log Death Rate 18-39 
	local r20_yrange ylabel(-0.02(0.005)0.02, labsize(medlarge))
	local r20_ytitlegap -55
	
	*r21
	local r21_x x2
	local r21_y log_death_rate_18_39_p1000_w
	local r21_fe fe2
	local r21_p p2
	local r21_l l1 
	local r21_xtitle Temperature (F)
	local r21_ytitle Log Death Rate 18-39
	local r21_yrange ylabel(-0.02(0.005)0.02, labsize(medlarge))
	local r21_ytitlegap -55
	
	*r30
	local r30_x x1
	local r30_y log_death_rate_gte40_p1000_w
	local r30_fe fe2
	local r30_p p1
	local r30_l l1 
	local r30_xtitle Temperature (F)
	local r30_ytitle Log Death Rate 40 and Above 
	local r30_yrange ylabel(-0.02(0.005)0.02, labsize(medlarge))
	local r30_ytitlegap -70
	
	*r31
	local r31_x x2
	local r31_y log_death_rate_gte40_p1000_w
	local r31_fe fe2
	local r31_p p2
	local r31_l l1 
	local r31_xtitle Temperature (F)
	local r31_ytitle Log Death Rate 40 and Above
	local r31_yrange ylabel(-0.02(0.005)0.02, labsize(medlarge))
	local r31_ytitlegap -70
	
	*r40
	local r40_x x1
	local r40_y log_death_rate_gte60_p1000_w
	local r40_fe fe2
	local r40_p p1
	local r40_l l1 
	local r40_xtitle Temperature (F)
	local r40_ytitle Log Death Rate 60 and Above
	local r40_yrange ylabel(-0.02(0.005)0.02, labsize(medlarge))
	local r40_ytitlegap -70
	
	*r41
	local r41_x x2
	local r41_y log_death_rate_gte60_p1000_w
	local r41_fe fe2
	local r41_p p2
	local r41_l l1 
	local r41_xtitle Temperature (F)
	local r41_ytitle Log Death Rate 60 and Above
	local r41_yrange ylabel(-0.02(0.005)0.02, labsize(medlarge))
	local r41_ytitlegap -70
	
	

	
	local plot_ops ylabel(,  angle(0) nogrid labcolor(gs4) tlcolor(gs4)) yline(0, lcolor(gs12)) graphregion(fcolor(white) lcolor(white)) plotregion(lstyle(white)) lp(solid) lw(medthick)  xlabel(, labcolor(gs4) tlcolor(gs4) labsize(medlarge) angle(45))  graphregion(margin(large)) vertical mcolor(gs1) ciopts(recast(rcap) lcolor(gs1))
	
	
	*define labels
	
	
		foreach run in `plotlist'{
			if "`run'" == "r10" | "`run'" == "r20" | "`run'" == "r30" | "`run'" == "r40" {
				local grow_index = "grow"
			}
			if "`run'" == "r11" | "`run'" == "r21" | "`run'" == "r31" | "`run'" == "r41"  {
				local grow_index = "all"
			}
			*l1
			
				foreach time_name in last_y`grow_index' this_y`grow_index'{
					local l1 zeros`time_name' = "<70" tmax_70_80`time_name' = "70-80" tmax_80_90`time_name' = "80-90" tmax_90_100`time_name' = "90-100"  tmax_100_110`time_name' = "100-110" tmax_gt110`time_name' = "{&ge}110"
					*plot graphs where data is not missing any rice or wheat for consistency
					*use when including rice and wheat specific results 
					cd `output'
					estimates use regols_nfhs_age_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2012_2019_distcluster
					insheet using regols_nfhs_age_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2012_2019_distcluster.txt, clear
					set scheme s2mono
					gen num_obs = e(N)
					format num_obs %9.0fc
					tostring num_obs, replace force usedisplayformat
					cd `table_coef_path'
					drop num_obs
					coefplot, keep(*: *`time_name') drop(rain_shock* ) omitted ``run'_order' xtitle(``run'_xtitle', color(gs1) size(medlarge)) ytitle(``run'_ytitle', placement(n) orientation(horizontal) color(gs1) size(medlarge)) `plot_ops' coeflabels(```run'_l'') ysc(titlegap(``run'_ytitlegap') outergap(0) lcolor(gs1)) ``run'_yrange'
					gr_edit yaxis1.title.DragBy 5 0
					cd `graph_path'
					graph export coefplot_regols_nfhs_age_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2012_2019_distcluster_`time_name'.pdf, replace	
			}
	}
		
}





***************************
*
*plot_reghdfe_icrisat
*
*plot regressions for icrisat
*yield outcomes
*
***************************
if "`plot_reghdfe_icrisat'" == "yes"{
	local plotlist
	foreach num of numlist 1 2{
		local plotlist `plotlist' r`num'
	}
	
	*define regressions
	*r1
	local r1_x x1
	local r1_y lyield
	local r1_fe fe1
	local r1_p p2
	local r1_l l1 
	local r1_xtitle Temperature (F)
	local r1_ytitle 100 x Log Yield 
	local r1_drop drop(_cons wet* dry*) keep(*:) omitted
	local r1_yrange ylabel(-4(1)0, labsize(medlarge))
	local r1_ytitlegap -35
	
	*r2
	local r2_x x1
	local r2_y lyield_m
	local r2_fe fe1
	local r2_p p2
	local r2_l l1 
	local r2_xtitle Temperature (F)
	local r2_ytitle 100 x Log Yield (Monsoon Crops) 
	local r2_drop drop(_cons wet* dry*) keep(*:) omitted
	local r2_yrange ylabel(-4(1)0, labsize(medlarge))
	local r2_ytitlegap -70
	

	
	local plot_ops ylabel(,  angle(0) nogrid labcolor(gs4) tlcolor(gs4)) yline(0, lcolor(gs12)) graphregion(fcolor(white) lcolor(white)) plotregion(lstyle(white)) lp(solid) lw(medthick)  xlabel(, labcolor(gs4) tlcolor(gs4) labsize(medlarge))  graphregion(margin(large)) vertical mcolor(gs1) ciopts(recast(rcap) lcolor(gs1))
	
	foreach grow_index in grow nogrow{
	*define labels
	
	*l1
	local l1 zerosthis_y`grow_index' = "<70" tmax_70_80this_y`grow_index' = "70-80" tmax_80_90this_y`grow_index' = "80-90" tmax_90_100this_y`grow_index' = "90-100"  tmax_100_110this_y`grow_index' = "100-110" tmax_gt110this_y`grow_index' = "{&ge}110"
	
		foreach run in `plotlist'{
			foreach sample in all{
				foreach time_name in this_y`grow_index'{
					cd `output'
					estimates use regols_icrisat_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2000_2011_distcluster_`sample'
					insheet using regols_icrisat_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2000_2011_distcluster_`sample'.txt, clear
					set scheme s2mono
					gen num_obs = e(N)
					format num_obs %9.0fc
					tostring num_obs, replace force usedisplayformat
					cd `table_coef_path'
					export delim num_obs using "`run'_``run'_y'_numobs_`sample'.txt"  if _n == 1, novarnames replace delimiter(" ")
					drop num_obs
					coefplot, keep(*: *`time_name') drop(rain_shock* ) omitted ``run'_order' xtitle(``run'_xtitle', color(gs1) size(medlarge)) ytitle(``run'_ytitle', placement(n) orientation(horizontal) color(gs1) size(medlarge)) `plot_ops' coeflabels(```run'_l'') ysc(titlegap(``run'_ytitlegap') outergap(0) lcolor(gs1)) ``run'_yrange'
					gr_edit yaxis1.title.DragBy 5 0
					cd `graph_path'
					graph export coefplot_regols_icrisat_`run'_``run'_y'_``run'_x'_``run'_fe'_2000_2011_distcluster_`sample'_`time_name'.pdf, replace
					
			}
		}
	}
		
}
}




***************************
*
*plot_reghdfe_thresholds
*
*plot threshold regressions 
*into one graph
*
***************************
if "`plot_reghdfe_thresholds'" == "yes"{

	local plotlist_c
	local plotlist_i
	local plotlist_p
	local plotlist_z
	local plotlist_t
	local plotlist_r
	local plotlist_n
	local plotlist_a
	foreach num of numlist  50(10)150{
		local plotlist_c `plotlist_c' rrc`num' 
		local plotlist_i `plotlist_i' rri`num' 
		local plotlist_p `plotlist_p' rrp`num' 
		local plotlist_z `plotlist_z' rrz`num' 
		local plotlist_t `plotlist_t' rrt`num' 
		local plotlist_r `plotlist_r' rrr`num' 
		local plotlist_n `plotlist_n' rrn`num' 
		local plotlist_a `plotlist_a' rra`num' 		
	}
		
	foreach num of numlist 50(10)150{
		*calories regression
		local rrc`num'_x x2
		local rrc`num'_y calories_lt`num'p
		local rrc`num'_fe fe1
		local rrc`num'_p p1
		local rrc`num'_thr `num'
		
		*iron regression
		local rri`num'_x x2
		local rri`num'_y iron_lt`num'p
		local rri`num'_fe fe1
		local rri`num'_p p1
		local rri`num'_thr `num'
		
		*protein regression
		local rrp`num'_x x2
		local rrp`num'_y protein_lt`num'p
		local rrp`num'_fe fe1
		local rrp`num'_p p1
		local rrp`num'_thr `num'
		
		*zinc regression
		local rrz`num'_x x2
		local rrz`num'_y zinc_lt`num'p
		local rrz`num'_fe fe1
		local rrz`num'_p p1
		local rrz`num'_thr `num'
		
		*calories regression
		local rrt`num'_x x2
		local rrt`num'_y thiamine_lt`num'p
		local rrt`num'_fe fe1
		local rrt`num'_p p1
		local rrt`num'_thr `num'
		
		*iron regression
		local rrr`num'_x x2
		local rrr`num'_y riboflavin_lt`num'p
		local rrr`num'_fe fe1
		local rrr`num'_p p1
		local rrr`num'_thr `num'
		
		*protein regression
		local rrn`num'_x x2
		local rrn`num'_y niacin_lt`num'p
		local rrn`num'_fe fe1
		local rrn`num'_p p1
		local rrn`num'_thr `num'
		
		*zinc regression
		local rra`num'_x x2
		local rra`num'_y ascorbic_acid_lt`num'p
		local rra`num'_fe fe1
		local rra`num'_p p1
		local rra`num'_thr `num'
	}
	

	
	local plot_ops ylabel(-0.6(0.2)0.8,  angle(0) nogrid labcolor(gs4) tlcolor(gs4)) yline(0, lcolor(gs12)) graphregion(fcolor(white) lcolor(white) margin(large)) plotregion(lstyle(white)) lp(solid) lw(medthick)  xlabel(50(10)150, labcolor(gs4) tlcolor(gs4) labsize(medlarge)) mcolor(gs1)
	
	
		*local xl  0 "Current" 1 "1-25" 2 "26-50" 3 "51-75" 4 "76-100" 5 "101-125" 6 "126-150"

		foreach nut_letter in i c p z t r n a{
			if "`nut_letter'" == "i"{
				local nutrient = "Iron"
			}
			if "`nut_letter'" == "c"{
				local nutrient = "Calories"
			}
			if "`nut_letter'" == "p"{
				local nutrient = "Protein"
			}
			if "`nut_letter'" == "z"{
				local nutrient = "Zinc"
			}
			if "`nut_letter'" == "t"{
				local nutrient = "Thiamine"
			}
			if "`nut_letter'" == "r"{
				local nutrient = "Riboflavin"
			}
			if "`nut_letter'" == "n"{
				local nutrient = "Niacin"
			}
			if "`nut_letter'" == "a"{
				local nutrient = "Ascorbic Acid"
			}
			tempfile predictions_`nut_letter' 
			foreach run in `plotlist_`nut_letter''{
				display "`run'"
				
				*load in toydata
				cd `path'/output
				insheet using rii_thresholds_dummydata.csv, clear			
				cd `output'
				estimates use regols_`run'_``run'_y'_``run'_x'_``run'_p'_``run'_fe'_2003_2012_distcluster
				predict p
				predict se, stdp
				gen p_high = p + se*1.96
				gen p_low = p - se*1.96
				gen threshold = ``run'_thr'
				
				if "`run'" != "rr`nut_letter'50"{
					append using "`predictions_`nut_letter''"
				}
					save "`predictions_`nut_letter''", replace
				}

				cd `graph_path'
				twoway rcap p_high p_low threshold || scatter p threshold, xtitle(`nutrient' % Threshold, color(gs1)) ytitle(Households (%), placement(n) orientation(horizontal) color(gs1)) `plot_ops' legend(off)  ysc(titlegap(-40) outergap(0) lcolor(gs1)) xlabel(, labcolor(gs4) tlcolor(gs4) angle(30))
				gr_edit yaxis1.title.DragBy 5 0
				graph export thresholds_gt110coef_`nut_letter'_2003_2012_distcluster.pdf, replace 
		}
		
}






